Skip to content

Instantly share code, notes, and snippets.

@ElliotWood
Created March 28, 2013 02:10
Show Gist options
  • Save ElliotWood/5259940 to your computer and use it in GitHub Desktop.
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
//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