private async Task Run(TaskAction taskAction) { using (_taskAction = taskAction) { try { WaitingFor = $"Waiting for '{_taskAction.Name}'..."; Progress = -1; IsBusy = true; _events.PublishOnUIThread(TaskState.Started); await _taskAction.Run(new Progress<int>(p => Progress = p)); _events.PublishOnUIThread(TaskState.Completed); } catch (OperationCanceledException) { _events.PublishOnUIThread(TaskState.Canceled); } catch (Exception ex) { _events.PublishOnUIThread(TaskState.Faulted); var msg = new TaskExceptionMessage(_taskAction.Name, ex); _events.PublishOnUIThread(msg); if (!msg.Handled) throw; } finally { IsBusy = false; } } }
public void Handle(TaskExceptionMessage message) { Trace.TraceError("Could not execute '{0}': {1}", message.TaskName, message.Exception); MessageBox.Show($"Could not execute '{message.TaskName}': {message.Exception.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); }