Windows Forms UI Threading

I fixed a UI issue we were having where some work was being done and it was updating a progress bar, but it wasn’t correctly painting the rest of the labels and other static UI elements.  It’s best to let the UI do it’s thing on the main thread, and then spawn off a worker thread in the background, allowing them to communicate with each other through delegates.

Here is a very nicely done, informative article about delegates that I should have read (I probably would have gotten to my solution quicker and surpassed my trial and error issues):

I used the following two articles as a basis for my fix:

However, I didn’t end up using the MulticastDelegate class at all in my solution.  It’s not really necessary, and I couldn’t get it to work when I tried to extend or inherit from it.  The following article says you can’t anyway, unless you are a compiler or some similar tool:

This link has a cool helper class for asynchronous delegates, though I didn’t use it:

Good luck.

FOLLOWUP (05/21/09)I have some further clarifications about how to properly invoke delegates to a new background thread in this post:

BeginInvoke Methods and OneWay Attribute