Reputation: 1284
I have a windows service which runs unmanaged code (using DllImport
) in different threads.
Sometimes, the unmanaged code 'hangs'. Think of while (true) ;
. When that happens, I need to kill the entire process (which automatically starts another because it's a windows service).
Is Environment.Exit(int)
sufficient? Or will I need e.g. Environment.FailFast(string)
?
Edit: I am unable to 'test' this. The freezes happen randomly.
Upvotes: 1
Views: 806
Reputation: 21477
Yes. Environment.Exit will kill all the threads running in the current process, including the main thread (and the process itself).
Environment.FailFast will log an event into the Application Log and then kill the process and all of the threads in the current process.
Upvotes: 1
Reputation: 16433
From the official Microsoft documentation, Environment.Exit
:
Terminates this process and returns an exit code to the operating system.
More usefully, the documentation goes on to state:
It sounds like Environment.Exit
is perfectly sufficient for your needs.
Upvotes: 1