Created
March 19, 2009 08:45
-
-
Save thbar/81652 to your computer and use it in GitHub Desktop.
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
/* the helper, built as a Control extension method */ | |
public delegate void Action(); | |
public static void InUIThread(this Control control, Action action) { | |
if (control.InvokeRequired) | |
control.EndInvoke(control.BeginInvoke(action)); | |
else | |
action(); | |
} | |
/* some real use from a form */ | |
class MyForm { | |
void SomeMethodRunningInABackgroundThread() { | |
/* some processing ... */ | |
this.InUIThread(() => { statusBar.Text = newStatus; } | |
/* more processing ... */ | |
this.InUIThread(() => { listBox.Items.Add(message); } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment