コード例 #1
0
        private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;

            DialogWindowHelper.ShowDialog("DispatcherUnhandledException", e.Exception.Message, OSKernel.Presentation.CustomControl.Enums.DialogSettingType.OnlyOkButton, OSKernel.Presentation.CustomControl.Enums.DialogType.Error);

            LogManager.Logger.Error(e.Exception);

            // 出现异常,但程序未关闭,主动关闭程序,避免卡死。
            if (Application.Current.MainWindow == null || !Application.Current.MainWindow.IsLoaded)
            {
                try
                {
                    this.Dispose();
                }
                finally
                {
                    LogManager.Logger.Info("退出系统");
                    Environment.Exit(0);
                }
            }
        }
コード例 #2
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            DialogWindowHelper.ShowDialog("DispatcherUnhandledException", e.ExceptionObject.ToString(), OSKernel.Presentation.CustomControl.Enums.DialogSettingType.OnlyOkButton, OSKernel.Presentation.CustomControl.Enums.DialogType.Error);

            LogManager.Logger.Error(e.ExceptionObject);

            if (e.IsTerminating)
            {
                Task.Run(async() =>
                {
                    try
                    {
                        Dispose();
                    }
                    finally
                    {
                        await Task.Delay(2000);
                        Environment.Exit(0);
                    }
                });
            }
        }