private static async Task HandleClosingErrorAsync(Window window, Exception ex) { var message = string.IsNullOrEmpty(ex.Message) ? ex.ToString() : ex.Message; IsClosingConfirmed = false; var closingDetails = new ClosingDetails { Window = window, Exception = ex, CanBeClosed = true, CanKeepOpened = true, Message = $"Error. The application will be forced to close:\n{message}" }; foreach (var watcher in Watchers) { watcher.ClosingFailed(closingDetails); } if (string.IsNullOrEmpty(closingDetails.Message) && !closingDetails.CanBeClosed && closingDetails.CanKeepOpened) { return; } var messageButton = MessageButton.OKCancel; if (!closingDetails.CanKeepOpened) { messageButton = MessageButton.OK; } if (await MessageService.ShowAsync(closingDetails.Message, "Error", messageButton, MessageImage.Error) == MessageResult.OK) { await CloseWindow(window).ConfigureAwait(false); } }
protected virtual void ClosingFailed(ClosingDetails appClosingFaultDetails) { }