Is there a way to find out if a WPF application is closing?

I am writing code that checks that my resources are cleaned up correctly.

When the application closes, the resources are not cleared, and this is normal. However, this makes my verification code fail.

Is there a way to find out if the WPF application is in the process of shutting down? - Something like Application.Current.IsShuttingDown?

+8
source share
2 answers

There is an Application.Exit event, you should be able to do this.

If you really need this property, then create a property in your App class (your class inheriting from Windows.Application ), and set it to true with the Application.Exit event.

+7
source
  /// <summary> /// Hack to check if the application is shutting down. /// </summary> public static bool IsShuttingDown() { try { Application.Current.ShutdownMode = Application.Current.ShutdownMode; return false; } catch (Exception) { return true; } } 
0
source

All Articles