none
ICLRRuntimeHost Start / Stop Thread RRS feed

  • Question

  • Hi

    My context si a Win32 App, which calls some .NET managed classes, through a flat C interface (note that,

    these .NET managed classes has some thread specific data).

    So to acheive this, I'm trying to use the technique "Loading the Common Language Runtime into a Process" (http://msdn.microsoft.com/en-us/library/vstudio/01918c6x(v=vs.100).aspx).

    The CLR Srart correctly, execution goes fine... the problem which remains is at finalization. When I call ICLRRuntimeHost->Stop(), I'm still on the main thread but, as I come in the .NET managed assembly, the classes destructors are called on another thread which is listed as "Thread GC Finalizer" !

    How can I control this, and have the classes destructors called on the same thread constructors have been launched ?

    Thanks in advance


    Nico F.

    Friday, July 11, 2014 12:30 PM

Answers

  • "Well, calling ICLRRuntimeHost:Stop method actually does release resources, since the destructor of a singleton gets called, but not on the same thread..."

    Finalizers always run on a different, dedicated thread. If you expect something to happen on a particular thread do not rely on finalizers. In general, do not rely on finalizers for anything, they're only intended to be used to prevent leaks caused by failure to release resource appropriately (by using Dispose or other specific mechanisms).

    Tuesday, July 15, 2014 1:58 PM
    Moderator

All replies

  • Hi Nico,

    ICLRRuntimeHost:Stop method does not  release resources to the host, unload application domains, or destroy threads.  You must terminate the process to release these resources. It just stops the execution of code by CLR. You can find the above information form MSDN. See important section in page below. http://msdn.microsoft.com/en-us/library/ms164416(v=vs.110).aspx.

    So, per my understanding, you need to release all resources using managed code before you call this method. See how to create and terminate threads from http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.90).aspx.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, July 14, 2014 2:01 AM
    Moderator
  • Hi, 

    Thanks for your answer.

    Well, calling ICLRRuntimeHost:Stop method actually does release resources, since the destructor of a singleton gets called, but not on the same thread... but, maybe this is errornous.

    Anyways, I'd look the topic "how to create and terminate thread" but, It's not applicable to my context (I'm in a win32 applicaiton, no .NET Framework...



    Nico F.

    Tuesday, July 15, 2014 12:51 PM
  • "Well, calling ICLRRuntimeHost:Stop method actually does release resources, since the destructor of a singleton gets called, but not on the same thread..."

    Finalizers always run on a different, dedicated thread. If you expect something to happen on a particular thread do not rely on finalizers. In general, do not rely on finalizers for anything, they're only intended to be used to prevent leaks caused by failure to release resource appropriately (by using Dispose or other specific mechanisms).

    Tuesday, July 15, 2014 1:58 PM
    Moderator
  • Hi, 

    Thanks for your answer.

    I'll look for a way to manage that.

    Thanks !


    Nico F.

    Wednesday, July 16, 2014 3:36 PM