Created
April 18, 2013 17:18
-
-
Save Khubajsn/5414532 to your computer and use it in GitHub Desktop.
Finally found a way to quickly and efficiently manipulate windows form controls from another thread - doing this without invoking the control results in an exception.
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
| using System.Threading; | |
| private void button1_Click(object sender, EventArgs e) | |
| { | |
| testingLabel.Text = "Thread started."; | |
| Thread t = new Thread(doTheMagic); | |
| t.Start(); | |
| } | |
| private void doTheMagic() | |
| { | |
| Thread.Sleep(5000); | |
| testingLabel.Invoke((Action)delegate | |
| { | |
| testingLabel.Text = "Works!"; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment