示例#1
0
        private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            Log.Error("{Exception}", e.Exception);

            var messageBox = new MessageBoxModel
            {
                Text    = $"An unhandled exception occurred: {e.Exception.Message}",
                Caption = "Fatal Error",
                Icon    = MessageBoxImage.Error,
                Buttons = new[]
                {
                    MessageBoxButtons.Custom("Reset Settings", EErrorKind.ResetSettings),
                    MessageBoxButtons.Custom("Restart", EErrorKind.Restart),
                    MessageBoxButtons.Custom("OK", EErrorKind.Ignore)
                },
                IsSoundEnabled = false
            };

            MessageBox.Show(messageBox);
            if (messageBox.Result == MessageBoxResult.Custom && (EErrorKind)messageBox.ButtonPressed.Id != EErrorKind.Ignore)
            {
                if ((EErrorKind)messageBox.ButtonPressed.Id == EErrorKind.ResetSettings)
                {
                    UserSettings.Delete();
                }

                ApplicationService.ApplicationView.Restart();
            }

            e.Handled = true;
        }