[WinForms] Full details of InvokeRequired/Invoke/BeginInvoke, common usage scenarios, and some issues you might not know about.

This is a really big article on all of the operational details of the WinForms marshalling pump (aka the plumbing for Invoke and BeginInvoke).  WinForms UI Thread Invokes: An In-Depth Review of Invoke/BeginInvoke/InvokeRequred

Abstract:
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.

I've talked about the pump before, but now I explain it in full gruesome detail.  Some notes are how this Awesome Windows Forms message pump trick... can actually fail and how this Got strange messages in your queue? Maybe Winforms is using it to synchronize your async code onto the UI thread... is only the tip of the iceberg (and what convinced me to write the full article).

Published Wednesday, May 05, 2004 3:06 AM by Justin Rogers

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)