Thread Safe update of StatusStrip progress bar

mskeel

Senior Contributor
Joined
Oct 30, 2003
Messages
913
.Net 2.0 question.

I've got all my heavy operations cranking in a worker thread but I want to display occasional updates to the user through a progress bar in the status strip on my form. The problem is that updating the progress bar from the WorkerThread's update event throws an unsafe update exception becuase the owner of the progress bar is someone other than the thread it is being used from.

I found this code to safely update a control across threads, but the status strip version of the progress bar doesn't have the InvokeRequired method. What's another method for safely updating across threads or am I going about this all wrong?
 
PlausiblyDamp said:
Winforms under .Net 2.0 also has a backgroundworker component (or something like that) - only dabbled with it but it might make your life easier.
It certianly did. Dropping that component in helped me clean up a lot of threading code. Now I can handle everything in a few crucial events for the component. This is the only thing that I'm having troubles with using the backgroundWorker component. Everything else has worked like a charm.
 
I just found this thread again and realized I never found a good solution. As a work around, I ended up not using the status strip progress bar.

Is there a way to do a thread safe update of the status strip progress bar? Because without an InvokeRequired() method, I'm not really sure how to go about this. Maybe throw an event that is caught by the display thread and do the update from there?
 
You can just check Form.InvokeRequired. It will return the same value that a StatusStrip would.
 
Back
Top