views:

283

answers:

2

I'm working on a mixed managed/native application using c++/CLI.

I know that the CLR will suspend all managed threads on (a clean) shutdown, but what about the unmanaged ones? Is it possible for the unmanaged threads to still be running, while the CLR runtime is shutting down/freeing memory/running finalizers?

A: 

Note that the CLR will only suspend managed threads with property IsBackGround set to true. Any foreground threads that are still running will leave the application 'hanging' waiting for all foreground threads to finish.

As far as unmanaged threads are concerned, the CLR has no way of knowing about them, so yes, they will continue running unless you write code to terminate them.

May I ask why your application cannot shut down the threads gracefully at the point where it decides to terminate rather than leaving it up to the environment to do your cleanup?

jerryjvl
Unfortunately I have little control over the legacy code we're using so graceful shutdown will be difficult.
Hrvoje Prgeša
A: 

I found further information on this issue:

Managed and Unmanaged Threading in Microsoft Windows

Process shutdown in c++/CLI mixed executable

Hrvoje Prgeša