Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Application.Exit() kill background threads?

I created a form which runs multiple background threads. I added another class which handles exceptions and errors if any. When the code runs, if an error occurs that should force the application to close can I just use Application.Exit()? Will that kill the background threads as well?

like image 316
Mohamed Avatar asked Nov 05 '25 06:11

Mohamed


1 Answers

No, it will not. Application.Exit() will simply force the windows message pump to post a Quit message, which will terminate your application's main thread. However, the process itself will continue to run until the background threads complete.

Update: as commenters have correctly pointed out, if your thread's IsBackground property is set to True, terminating the main thread via Application.Exit() will shut down the process.

like image 122
pdriegen Avatar answered Nov 06 '25 19:11

pdriegen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!