Skip to content

Instantly share code, notes, and snippets.

@Sheepings
Created November 10, 2019 01:53
Show Gist options
  • Save Sheepings/32e60bdec67d45f79913f8576989fd95 to your computer and use it in GitHub Desktop.
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
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