我正在编写一些代码来检查我的资源是否已正确清理.
当应用程序关闭时,资源不会被清除,这很好.但是,这使我的检查代码失败.
有没有办法知道WPF应用程序是否正在关闭? - 像Application.Current.IsShuttingDown这样的东西?
有Application.Exit事件,你应该能够做到这一点.
如果您真的需要它作为属性,那么在您的App类中创建一个属性(您的类继承Windows.Application)并将其设置为true in the Application.Exitevent.
/// <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;
}
}
Run Code Online (Sandbox Code Playgroud)