Multithreading in Windows Forms
Much of the .NET framework is not considered thread-safe. This means that it isn't safe to invoke operations directly from one thread to a method in a .NET framework class. This is especially true of Windows Forms controls.
However, this doesn't mean you can't use multithreading in Windows Forms applications; it just means you have to be careful when you do. When interacting with the .NET framework, you need to use the synchronous Invoke or asynchronous BeginInvoke and EndInvoke methods to interact with Windows Forms controls. (You can call Invoke, BeginInvoke, EndInvoke, and CreateGraphics across threads safely.)
Listing 6.13 demonstrates how to interact with Windows Forms. The code simulates an animated graphic. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access