Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 461
Robert Fraser Avatar asked Dec 03 '22 02:12

Robert Fraser


1 Answers

System.Environment.HasShutdownStarted

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

like image 199
Philippe Avatar answered Dec 24 '22 00:12

Philippe