Created
November 10, 2019 01:53
-
-
Save Sheepings/32e60bdec67d45f79913f8576989fd95 to your computer and use it in GitHub Desktop.
This is a basic multithreading template which demonstrates how to update your UI from a non UI 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
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Shown(object sender, EventArgs e) | |
{ | |
void updateUI() | |
{ | |
UpdateResponse(); | |
} | |
new Thread(updateUI).Start(); | |
} | |
public delegate void Callback(string text); | |
private void UpdateResponse() | |
{ | |
StringBuilder sb = new StringBuilder(); | |
sb.Append("My message"); | |
Invoke(new Callback(UpdateMethod), new object[] { (sb.ToString()) }); | |
} | |
private void UpdateMethod(string responsiveMsg) | |
{ | |
textBox1.Text = responsiveMsg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment