// The TAP async version of OnNotifyPaused() above. protected async Task OnNotifyPausedAsync() { WorkflowInstanceState workflowInstanceState = Controller.State; if (workflowInstanceState == WorkflowInstanceState.Aborted) { // If there were a OnRequestAbort() previously, notify the host now. if (onRequestAbortReason != null) { await NotifyHostOnUnhandledExceptionAsync(onRequestAbortReason, null); } } else { try { // If it's completed, call OnCompletedAsync() on host. if (workflowInstanceState == WorkflowInstanceState.Complete && !hasRaisedCompleted) { await IfHasPendingThenFlushTrackingRecordsAsync(); hasRaisedCompleted = true; ActivityInstanceState completionState; IDictionary <string, object> outputs; Exception terminationException; completionState = Controller.GetCompletionState(out outputs, out terminationException); await host.OnCompletedAsync(completionState, outputs, terminationException); } // Call OnPausedAsync() on INotificationParticipant extensions. await OnPausedAsync(); // Track the Idle state. if (workflowInstanceState == WorkflowInstanceState.Idle && Controller.TrackingEnabled) { Controller.Track(new WorkflowInstanceRecord(Id, WorkflowDefinition.DisplayName, System.Activities.Tracking.WorkflowInstanceStates.Idle, DefinitionIdentity)); await IfHasPendingThenFlushTrackingRecordsAsync(); } // If required, save state. if (Controller.IsPersistable) { if (IdlePersistenceModeExtensions.ShouldSave(Parameters.IdlePersistenceMode, workflowInstanceState, IsStarting)) { await SaveAsync(); } IsStarting = false; } } catch (Exception e) { // Notify host, this can be eg. a serialization exception! await NotifyHostOnUnhandledExceptionAsync(e, null); // TODO Do we really need to protect againts exceptions below? Theoretically Controller won't throw now. // The instance will abort, independently from the configuration. await ExecuteWithExceptionTrackingAsync(() => { return(AbortAsync(e)); }); workflowInstanceState = Controller.State; } } // finally // TODO Do we really need to protect againts exceptions below? Theoretically Controller won't throw now. await ExecuteWithExceptionTrackingAsync(() => { // At this point it is possible, that Cancel/Teminate was called by OnNotifyUnhandledException() or OnNotifyPaused(), // and controller/executor Run() should be called, in this case we won't set the reset event, // the Run() will result a callback to OnNotifyPaused() or OnNotifyUnhandledException() again. if (workflowInstanceState == WorkflowInstanceState.Runnable) { return(RunAsync()); } else { host.OnNotifyIdle(); return(TaskConstants.Completed); } }); }