Should I use Invoke or SynchronizationContext to update form controls from another thread?

I prefer SynchronizationContext over Control. Invoke The danger of Control. Invoke is that there is a lifetime issue with the owning Control If the Control is disposed while you are trying to Invoke on it then it compromises the ability of the call to succeed.

This happens when dialogs are closed, views shifted, etc.

I prefer SynchronizationContext over Control.Invoke. The danger of Control. Invoke is that there is a lifetime issue with the owning Control.

If the Control is disposed while you are trying to Invoke on it then it compromises the ability of the call to succeed. This happens when dialogs are closed, views shifted, etc ... SynchronizationContext. Current though generally lives as long as the thread it's associated with.It does have a finite lifetime and hence ultimately the same problems but it's a bit more predictable than a Control.

For long running tasks that shouldn't tie up the UI it is a clean and easy way to get multithreading capabilites. For instance you can perform updates to the UI using the ProgressChanged Event and the background worker and the background worker class will ensure that the thread that created the BW is the one that executes the ProcessChanged and WorkComplete event.So if you made the BW from the UI and set it off to work then you can update the UI safely from there. Here's a quick article from MS msdn.microsoft.com/en-us/library/cc22140... Another really good link albahari.com/threading/part3.aspx#_Backg....

I am familiar with the BackgroundWorker but this project is for a server application so Tasks/ThreadPool is more suitable for this I believe. Otherwise you are correct though. Probably should have included that in the original post.My apologies.

– John Smith Sep 20 at 5:53 @John Why do you have UI controls on a server application? – adrianm Sep 20 at 11:06 After reading the question a second time I'm thinking John is asking two questions here.1 is using Synchronization and two is best way to handle multithreading in UI – Jason Turan Sep 21 at 1:26.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions