Is it necessary to end a ThreadPool on Application.Exit()?

1.2k views Asked by At

I have a separate BackgroundWorker and ThreadPool that does methods in the background. (BackgroundWorker for UI feedback)

ThreadPool:

ThreadPool.QueueUserWorkItem(foo, null);

I understand that I need to safely terminate my BackgroundWorker using a flag considering that it gives me an Exception if ever I close it without one. However, the ThreadPool does not. (Closing doesn't throw any Exception)

BackgroundWorker_DoWork:

while (_isFinished)
{
    // Do stuff
}

So is it necessary to do the same precaution with the ThreadPool?

Thanks in advance.

1

There are 1 answers

0
AudioBubble On BEST ANSWER

No.

ThreadPool threads, according to MSDN, are background threads and will not keep the application alive after the main execution thread has exited. When the application exits, they stop executing as well.

Background threads also do not throw exceptions if closed during application shutdown.