public void CancelAsync(object userState) { if (userState == null) { throw Microsoft.CoreWf.Internals.FxTrace.Exception.ArgumentNull("userState"); } AsyncInvokeContext context = this.RemoveFromPendingInvokes(userState); if (context != null) { // cancel does not need a timeout since it's bounded by the invoke timeout if (s_cancelCallback == null) { s_cancelCallback = Fx.ThunkCallback(new AsyncCallback(CancelCallback)); } // cancel only throws TimeoutException and shouldnt throw at all if timeout is infinite // cancel does not need to raise InvokeCompleted since the InvokeAsync invocation would raise it IAsyncResult result = context.WorkflowApplication.BeginCancel(TimeSpan.MaxValue, s_cancelCallback, context); if (result.CompletedSynchronously) { context.WorkflowApplication.EndCancel(result); } } }
private void PostInvokeCompletedAndRemove(AsyncInvokeContext context, Exception error) { if (context.UserState != null) { RemoveFromPendingInvokes(context.UserState); } PostInvokeCompleted(context, error); }
private void CancelCallback(IAsyncResult result) { if (result.CompletedSynchronously) { return; } AsyncInvokeContext context = (AsyncInvokeContext)result.AsyncState; // cancel only throws TimeoutException and shouldnt throw at all if timeout is infinite context.WorkflowApplication.EndCancel(result); }
private void AddToPendingInvokes(AsyncInvokeContext context) { lock (ThisLock) { if (this.PendingInvokes.ContainsKey(context.UserState)) { throw Microsoft.CoreWf.Internals.FxTrace.Exception.AsError(new InvalidOperationException(SR.SameUserStateUsedForMultipleInvokes)); } this.PendingInvokes.Add(context.UserState, context); } }
private void PostInvokeCompleted(AsyncInvokeContext context, bool cancelled, Exception error) { InvokeCompletedEventArgs e = new InvokeCompletedEventArgs(error, cancelled, context); if (this.InvokeCompleted == null) { context.Operation.OperationCompleted(); } else { context.Operation.PostOperationCompleted(this.RaiseInvokeCompletedCallback, e); } }
private void PostInvokeCompleted(AsyncInvokeContext context, Exception error) { bool cancelled; if (error == null) { context.WorkflowApplication.GetCompletionStatus(out error, out cancelled); } else { cancelled = false; } PostInvokeCompleted(context, cancelled, error); }
private void InternalInvokeAsync(IDictionary <string, object> inputs, TimeSpan timeout, object userState) { AsyncInvokeContext context = new AsyncInvokeContext(userState, this); if (userState != null) { AddToPendingInvokes(context); } Exception error = null; bool completedSynchronously = false; try { if (s_invokeCallback == null) { s_invokeCallback = Fx.ThunkCallback(new AsyncCallback(InvokeCallback)); } context.Operation.OperationStarted(); IAsyncResult result = WorkflowApplication.BeginInvoke(_workflow, inputs, _extensions, timeout, SynchronizationContext.Current, context, s_invokeCallback, context); if (result.CompletedSynchronously) { context.Outputs = this.EndInvoke(result); completedSynchronously = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } error = e; } if (error != null || completedSynchronously) { PostInvokeCompletedAndRemove(context, error); } }
private void InvokeCallback(IAsyncResult result) { if (result.CompletedSynchronously) { return; } AsyncInvokeContext context = (AsyncInvokeContext)result.AsyncState; WorkflowInvoker thisPtr = context.Invoker; Exception error = null; try { context.Outputs = thisPtr.EndInvoke(result); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } error = e; } thisPtr.PostInvokeCompletedAndRemove(context, error); }
internal InvokeCompletedEventArgs(Exception error, bool cancelled, AsyncInvokeContext context) : base(error, cancelled, context.UserState) { this.Outputs = context.Outputs; }