public async Task ExecuteTask(object parameter) { if (CanExecute == false) return; using (LogContext.PushProperty("Initiator", GetType().Name)) using (Log.Logger.BeginTimedOperation("Executing " + GetType().Name, warnIfExceeds: TimeSpan.FromSeconds(5))) { IsExecuting = true; NotifyOfPropertyChange(() => IsExecuting); RaiseCanExecuteChanged(); try { await ExecuteAsync(parameter); } catch (Exception ex) { var args = new AsyncActionErrorArgs(); ExecuteOnError(ex, args); if (!args.IsHandled) Caliburn.Micro.Execute.BeginOnUIThread(() => { throw new Exception("Failed executing {0}: {1}".FormatWith(GetType().Name, ex.Message), ex); }); } finally { IsExecuting = false; NotifyOfPropertyChange(() => IsExecuting); RaiseCanExecuteChanged(); } } }
public async Task ExecuteTask(object parameter) { if (CanExecute == false) { return; } using (LogContext.PushProperty("Initiator", GetType().Name)) using (Log.Logger.BeginTimedOperation("Executing " + GetType().Name, warnIfExceeds: TimeSpan.FromSeconds(5))) { IsExecuting = true; NotifyOfPropertyChange(() => IsExecuting); RaiseCanExecuteChanged(); try { await ExecuteAsync(parameter); } catch (Exception ex) { var args = new AsyncActionErrorArgs(); ExecuteOnError(ex, args); if (!args.IsHandled) { Caliburn.Micro.Execute.BeginOnUIThread(() => { throw new Exception("Failed executing {0}: {1}".FormatWith(GetType().Name, ex.Message), ex); }); } } finally { IsExecuting = false; NotifyOfPropertyChange(() => IsExecuting); RaiseCanExecuteChanged(); } } }
protected virtual void ExecuteOnError(Exception e, AsyncActionErrorArgs args) { }