Update UI state from an another Thread in Windows Forms
1001binary
Posted on April 9, 2021
An exception is thrown when trying to update control state from an another Thread.
Thread newThread = new Thread(new ThreadDelegate(() => {
txtStatus.Text = "Started";
}));
newThread.Start();
Solution
We use BeginInvoke to update UI state asynchronously.
Thread newThread = new Thread(new ThreadDelegate(() => {
txtStatus.BeginInvoke(() =>
{
txtStatus.Text = "Started";
});
}));
newThread.Start();
Happy coding!
💖 💪 🙅 🚩
1001binary
Posted on April 9, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.