Skip to content

Instantly share code, notes, and snippets.

@uugan
Created November 15, 2017 05:32
Show Gist options
  • Save uugan/b06b39333a820a451b3134af5a75bc80 to your computer and use it in GitHub Desktop.
Save uugan/b06b39333a820a451b3134af5a75bc80 to your computer and use it in GitHub Desktop.
C# control extention for invoke methods
public static class ControlExtentions
{
public static void InvokeIfNeeded(this Control control, Action doit)
{
if (control.InvokeRequired)
control.Invoke(doit);
else
doit();
}
public static void InvokeIfNeeded<T>(this Control control, Action<T> doit, T arg)
{
if (control.InvokeRequired)
control.Invoke(doit, arg);
else
doit(arg);
}
}
/*
example of usage:
textBox1.InvokeIfNeeded(() => textBox1.Text = "bla");
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment