by Mark Shiffer
11/20/2007 8:26:00 AM
I recently came across this tid-bit of information and thought I would document it for myself. Windows Forms controls are not thread safe. Therefore, when attempting to update a control from another thread you must take special precautions. An example of where this would be helpful would be in updating a progress bar or other UI control when running a batch process on another thread. To accomplish this, the InvokeRequired property of the control should be used along with the Invoke or BeginInvoke method. Invoke required will return True when the caller is on a different thread then the control was created on. In that case, you then need to call Invoke with a delegate that will get run on the control's thread.