WinForms UI Thread Invokes
WinForms UI Thread Invokes: An In-Depth Review of Invoke/BeginInvoke/InvokeRequred
A very good read
http://weblogs.asp.net/justin_rogers/articles/1263...
Marshalling the execution of your code onto the UI thread in the Windows Forms environment is critical to prevent cross-thread usage of UI code. Most people don't understand how or when they'll need to use the marshalling behavior or under what circumstances it is required and when it is not. Other users don't understand what happens when you use the marshalling behavior but it isn't needed. In actuality it has no negative effects on stability, and instead reserves any negative side effects to performance only.
Understanding the semantics of when your callback methods will be called, in what order, and how might be very important to your application. In addition to the default marhalling behavior, I'll be covering special considerations for enhancing the marhsalling behavior once we fully understand how it works. We'll also cover all of the normal scenarios and uses for code execution marhsalling to make this a complete Windows Forms marshalling document.
TOC:
- UCS 1: Using InvokeRequired and Invoke for Synchronous Marshalling, the default scenario
- UCS 2: Using BeginInvoke for Asynchronous Marshalling
- InvokeRequired and how it works
- Invoke operation on the UI thread and from a different thread
- InvokeMarshaledCallbacks and how it handles the callback queue
- BeginInvoke operation on the UI thread and from a different thread
- UCS 3: Using BeginInvoke to change a property after other events are processed, and why it can fail
- Public and Internal Methods covered with a short description of what they do
- Conclusion