Created
May 20, 2013 12:57
-
-
Save dkalamari/5612067 to your computer and use it in GitHub Desktop.
Update UI control from 2. thread
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
//Control.Invoke: Executes on the UI thread, but calling thread waits for completion before continuing. | |
//Control.BeginInvoke: Executes on the UI thread, and calling thread doesn't wait for completion. | |
//Normally every BeginXXX should have a corresponding EndXXX call, usually in the callback. | |
public void updateGuiFromWorkerThread(String message, Color color) | |
{ | |
Invoke(new StatusEventHandler(UpdateUI), new StatusArguments(message, color)); | |
} | |
private void UpdateUI(StatusArguments e) | |
{ | |
lblStatus.Text = "Status: " + e.message; | |
lblStatus.BackColor = e.color; | |
} | |
private delegate void StatusEventHandler(StatusArguments e); | |
private class StatusArguments : System.EventArgs | |
{ | |
public String message; | |
public Color color; | |
public StatusArguments(String message, Color color) | |
{ | |
this.message = message; | |
this.color = color; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment