We are building a .NET application using WinForms (3.5).
I have added a new feature recently, and started experiencing weird behavior when accessing certain controls. The problem was that some UI control access simply halted the execution (no exception was seen).
Under close examination (using WinDbg) I realized the controls were being updated from a ThreadPool thread, and a CrossThreadMessagingException was thrown.
My question is -- is there any good practice on how to circumvent such behavior?
It would be very cumbersome but also perhaps not possible to surround every code location that accesses UI controls with the Control.Invoke method.
How can i partition my code to "safe" code that shouldn't use Invoke, from one that should?