WindowsFormsSynchronizationContext – it’s all smoke, mirrors and PostMessage

March 11, 2010

Intrigue is curious thing, much as curiosity is intriguing. What drives it? Mostly just needing to know something for no other reason than wanting to know itself – curious indeed. 

So why would I really be bothered to know what WindowsFormsSyncronizationContext does under the hood? Well dear bleader (if someone who write blogs is a blogger, maybe someone who reads blogs is a bleader) I had my suspicions, but I just needed to find out.

SynchronizationContext and it’s derivatives was introduced in .NET 2.0 as simple .NET language construct to allow a non-GUI thread to call methods on a GUI control. Previously, code had to be written to perform the InvokeRequired, BeginInvoke, Invoke dance and as has been discovered, this has problems and  can have you chasing nasty bugs.

In I discussed BeginInvoke for delegates and controls, some issues and how they worked under the hood.

As I said before, I was suspicious that WindowsFormsSynchronizationContext worked pretty much the same way. And Lo, with a bit of windows message spying on a simple test app, my suspicions were confirmed. WindowsFormsSynchronizationContext.Post() and .Send() end up using PostMessage with registered windows messages, presumably using BeginInvoke and Invoke respectively to push the control method call onto the main GUI thread.  However, it does make the code earlier to write and as we all know, less code means less bugs.

Now to find out what happens in the Freemasons. I’m just curious you understand.


2 Responses to “WindowsFormsSynchronizationContext – it’s all smoke, mirrors and PostMessage”

  1. Luther Says:

    “Worked All Zones Award” is the same concept with time zones.
    Regular workshops ensure that the staff at PVM Radio subdivision is not only up to date with the latest technological innovations,
    but also ensures that the customers from diverse backgrounds are
    offered the best possible services to suit their tastes.
    Whats more is that 2G phones can come in a tinier and
    slimmer package, even its batteries.

  2. Wow, superb weblog layout! How lengthy have you ever been running a
    blog for? you made blogging glance easy. The entire glance of your website is magnificent, let alone the content material!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: