Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to a background worker that is still running when you close the form?

Or another facet to the questions is: should I be handling the possibility the form is closed when coding a background worker?

I have, for example, code that does an SQL query (which is not cancellable) in a background worker then when complete "boldifies" dates in a calendar control to match the dates returned from the query.

I'm curious what the background worker is designed to do in such a situation? - not fire the RunWorkerComplete event? - ignore calls to the dialog in the RunWorkerComplete function call because it's not a window any more?

like image 450
noelicus Avatar asked Dec 10 '12 10:12

noelicus


1 Answers

If the form you are closing is the main(in other words the only) form then the background worker thread will automatically close with the closing of application.

If it is not the main form then the background thread will keep on running. In this case you should manually abort the background thread with the closing of your form

like image 106
Haris Hasan Avatar answered Oct 26 '22 01:10

Haris Hasan