简体   繁体   中英

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?

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.

否。线程终止是协作的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM