Search code examples
c#.netdestructorfinalizerapplication-shutdown

C#: In a finalizer, how to find out if the application is shutting down?


I have a finalizer that seems to always fail during application shutdown. I think this is because it's holding onto some native resources that are no longer valid at that point. Is there a way to tell, in a destructor/finalizer, if it is being called due to an application shutdown?

Thanks!


Solution

  • System.Environment.HasShutdownStarted
    

    Documentation here: http://msdn.microsoft.com/en-us/library/system.environment.hasshutdownstarted.aspx