Created
March 28, 2013 02:10
-
-
Save ElliotWood/5259940 to your computer and use it in GitHub Desktop.
Async in winforms kinda sux
Here is a way better way to do it
This file contains 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
//static for extension.. | |
//this allows us to always make sure we're using our controls on the | |
//thread they were created on, regardless of the thread we're calling from... | |
public static class ISynchronizeInvokeExtensions | |
{ | |
public static void InvokeEx<T>(this T @this, Action<T> action) where T : ISynchronizeInvoke | |
{ | |
if (@this.InvokeRequired) | |
@this.BeginInvoke(action, new object[] { @this }); | |
else | |
action(@this); | |
} | |
} | |
//So now you can call it like: | |
Txtbox.InvokeEx(txt => { | |
txt.Text = "blah"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment