I have a Worker class and a MainForm/UI class. From the UI class I create a new instance of the Worker class in a new background thread. This thread marshals a few updates back to the UI's controls. Since they are in different classes I basically pass the MainForm instance (this) and an appropriate delegate to update the controls, into the worker class' constructor. In the constructor I set the mainForm to an ISynchronizeInvoke
object (call it _synch) and then, further down in the worker class I do _synch.Invoke(theDelegate, new object[] { "new value" })
.
That all works fine, but then I realized that it is also possible to do just simply mainForm.Invoke
(not using the ISynchronizeInvoke
object). What is the difference between the two?
To make matters worse I read in an article that ISynchronizeInvoke
is not really needed much anymore, now that SynchronizationContext
has come a long. I realize that I do not understand what these two are for. Any help with understanding why I should use Invoke on these objects as opposed to directly on the mainForm would be greatly appreciated.