Suppose you use a ThreadPool
to perform some operations and assume that each operation writes on a file. All threads of ThreadPool
are background threads, so they will be terminated when closing the application. What happens if the application is closed while a thread of ThreadPool
is writing a file to disk?
Operating system will close the file handle as the part of terminating the process.
Read the MSDN article on Foreground and Background threads
ThreadPool threads are background threads. From the article:
When the runtime stops a background thread because the process is shutting down, no exception is thrown in the thread.
The thread simply stops. It executes one instruction, and never executes the next. The FileStream will be closed as part of the CLR clearing up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With