Is there a way to know if a WPF application is shutting down?

前端 未结 3 1099
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 16:53

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

When the application is shutdown, resources are not cleaned up, which is fine. However, thi

3条回答
  •  青春惊慌失措
    2021-02-20 17:39

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

提交回复
热议问题