To port Michael Damatov's answer (C#) which is based on Herfried K. Wagner. (VB.NET) here is the C++/CLI version:
ref class MyClass
{
ref class StaticFinalizer sealed
{
!StaticFinalizer();
};
static initonly StaticFinalizer^ stDestr = gcnew StaticFinalizer();
}
MyClass::StaticFinalizer::!StaticFinalizer()
{
System::Diagnostics::Debug::WriteLine("In StaticFinalizer!");
}
P.S. Just like the AppDomain.ProcessExit method, this one may not be called if the process is terminated abnormally (from Task Manager for example).
Another word of caution is that if MyClass is generic (templated), the assumption that its static constructor and static destructor will be called no more than once per application execution is no longer be valid.