A sample that you might find useful is to check at the top of the functions that interact with the GUI to see if you are working in the correct thread or not, and activate the function if necessary. Like this:
public delegate void InvocationDelegate(); public void DoGuiStuff(){ if (someControl.InvokeRequired){ someControl.Invoke(InvocationDelegate(DoGuiStuff)); return; }
Using this template - if you are in the correct thread when the method is called, it does not call itself, but if you are in another thread, it will call itself and then return (therefore, the logic of manipulating the GUI only ever once).
Russell Troywest
source share