Search code examples
.netcom-interop

COM Callable Wrapper and .NET object lifetime


I have a c# .NET assembly that gets called from a C++ COM client. When the client process explicitely release the COM object, the CCW release it'sinternal reference, thus making the .NET object eligible for garbage collection.

What if the .NET object has a static constructor that open a log file ? Is there an elegant solution to close the log file without an explicit request from the client ?

TIA.


Solution

  • After some testing using AppDomain.ProcessExit EventHandler seems to be a good choice to close the log file.