/// <summary>Begins to continue the workflow.</summary> /// <param name="callback">The method to be called when the asynchronous continue operation is completed.</param> /// <param name="state">A user-provided object that distinguishes this particular asynchronous continue request from other requests.</param> /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous continue.</returns> public IAsyncResult BeginContinue(AsyncCallback callback, object state) { AsyncResultVoid result = new AsyncResultVoid(callback, state); ThreadPool.QueueUserWorkItem(this.ContinueWorkflowHelper, result); return(result); }
/// <summary>Waits for the pending asynchronous continue to complete.</summary> /// <param name="asyncResult">The reference to the pending asynchronous request to wait for.</param> /// <exception cref="NotSupportedException">The workflow does not support pausing and continuing.</exception> /// <exception cref="InvalidOperationException">The workflow is not in a state in which it can be continued. Only when the workflow is in the /// state <see cref="WorkflowState.Paused"/>, it can be continued.</exception> /// <seealso cref="CanPauseAndContinue"/> public void EndContinue(IAsyncResult asyncResult) { Guard.ArgumentIsNotNull(asyncResult, nameof(asyncResult)); AsyncResultVoid result = asyncResult as AsyncResultVoid; if (result == null) { throw new ArgumentException("The specified IAsyncResult was not of the expected type AsyncResultVoid", "asyncResult"); } result.EndInvoke(); return; }
/// <summary>Executes the <see cref="Continue()"/> method in a separate thread. This is used to support asynchronous operations.</summary> /// <param name="asyncResult">The object that holds the status of the asynchronous operation.</param> private void ContinueWorkflowHelper(object asyncResult) { AsyncResultVoid result = asyncResult as AsyncResultVoid; if (result == null) { throw new ArgumentException("The specified object was not of the expected type AsyncResultVoid", "asyncResult"); } try { this.Continue(); result.SetAsCompleted(null, false); } catch (Exception ex) { /* We deliberately catch every exception. It is up to the caller of EndContinue() to do a more fine-grained exception handling */ result.SetAsCompleted(ex, false); } }