Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save AlexArchive/724b6708d24defc910f2 to your computer and use it in GitHub Desktop.

Select an option

Save AlexArchive/724b6708d24defc910f2 to your computer and use it in GitHub Desktop.
public static class ControlExtensions
{
public static void Invoke(this Control control, MethodInvoker method)
{
if (control.InvokeRequired == false)
{
// The executing thread _is_ the thread that owns the control's underlying
// handle and as such, there is no need to marshall the method invocation.
method.Invoke();
}
else
{
control.Invoke(method);
}
}
public static void BeginInvoke(this Control control, MethodInvoker method)
{
if (control.InvokeRequired == false)
{
// The executing thread _is_ the thread that owns the control's underlying
// handle and as such, there is no need to marshall the method invocation.
method.Invoke();
}
else
{
control.BeginInvoke(method);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment