views:

105

answers:

2

I have a windows service written in dotNet. There is a worker service that spawns worker threads using various Delegate.BeginInvokes. When the service crashes are those threads going to be cleaned up automatically? And if so, when?

A: 

only when the service is terminated and unloaded from memory

Steven A. Lowe
Will the service unload even if there are threads still being executed?
Orion Adrian
@[Orion Adrian]: I doubt it. You really should take responsibility for managing your own app state ;-)
Steven A. Lowe
+1  A: 

All threads created by your process are inside that process. When your application crashes your process dies, and all threads in that process are terminated abruptly. They are not terminated friendly-like (they're not given an abort signal or anything), they are just killed. They may or may not be given enough processor time to finish executing -- rather depends on what they were doing, and how fast Windows dumps the process.

All robust versions of Windows (2000+) should have your process segregated, so when it dies the whole process space is dumped and the memory is reclaimed. If you were accessing unmanaged resources at the time of the crash, then the whole picture changes and the answer is "it depends".

sliderhouserules