Reputation: 624
Here is my Scenario:-
I have a BackGroundWorker Thread which is subscribed to 2 events DoWork and RunWorkerCompleted .What I am doing is in DoWork event I am doing timetaking task and Updating the UI that is Starting the Loader using MainThread and on RunWorkerComplete I am Updating My UI that is Stopping the Loader.
Now what I want to make sure that when my application gets terminated while the BackgroundWorker is ON that is loader is spinning.I want to make sure that it Kills the BakcgroundWorker Thread or at least the termination of the Application results in thread SAFE when the LOADER is ON.
Does Dispose will give any HElp..? or DynamicGarbageCollection will handle the unusedObjects when application termination occurs will do the same thing which Dispose does.??
Hope I am Clear..How can I achieve that.??
Upvotes: 0
Views: 213
Reputation: 3297
By definition, a background thread will not be able to keep the host process running (as opposed to a foreground thread - such as the thread that renders the UI components).
See the MSDN documentation: http://msdn.microsoft.com/en-us/library/h339syd0.aspx
Upvotes: 0
Reputation: 273784
The bgw thread itself will be stopped when your App terminates but you have to take care not to update controls on a Closed/Closing Form.
Do not call Dispose() here. You can Cancel the backgroundworker but the code in DoWork() must comply.
Upvotes: 1