Created
November 15, 2017 05:32
-
-
Save uugan/b06b39333a820a451b3134af5a75bc80 to your computer and use it in GitHub Desktop.
C# control extention for invoke methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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