public void CancelAsync(object userState) { if (userState == null) { throw 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 (cancelCallback == null) { 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, 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) { AsyncInvokeContext asyncState = (AsyncInvokeContext)result.AsyncState; asyncState.WorkflowApplication.EndCancel(result); } }
private void AddToPendingInvokes(AsyncInvokeContext context) { lock (ThisLock) { if (this.PendingInvokes.ContainsKey(context.UserState)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.SameUserStateUsedForMultipleInvokes)); } this.PendingInvokes.Add(context.UserState, context); } }
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 PostInvokeCompleted(AsyncInvokeContext context, bool cancelled, Exception error) { var 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 PostInvokeCompleted(AsyncInvokeContext context, Exception error) { bool flag; if (error == null) { context.WorkflowApplication.GetCompletionStatus(out error, out flag); } else { flag = false; } this.PostInvokeCompleted(context, flag, error); }
public void CancelAsync(object userState) { if (userState == null) { throw FxTrace.Exception.ArgumentNull("userState"); } AsyncInvokeContext state = this.RemoveFromPendingInvokes(userState); if (state != null) { if (cancelCallback == null) { cancelCallback = Fx.ThunkCallback(new AsyncCallback(this.CancelCallback)); } IAsyncResult result = state.WorkflowApplication.BeginCancel(TimeSpan.MaxValue, cancelCallback, state); if (result.CompletedSynchronously) { state.WorkflowApplication.EndCancel(result); } } }
private void InvokeCallback(IAsyncResult result) { if (!result.CompletedSynchronously) { AsyncInvokeContext asyncState = (AsyncInvokeContext)result.AsyncState; WorkflowInvoker invoker = asyncState.Invoker; Exception error = null; try { asyncState.Outputs = invoker.EndInvoke(result); } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } error = exception2; } invoker.PostInvokeCompletedAndRemove(asyncState, error); } }
/// <summary> /// Initializes a new instance of the <see cref="InvokeAsyncResult"/> class. /// </summary> /// <param name="activity">The activity.</param> /// <param name="inputs">The inputs.</param> /// <param name="extensions">The extensions.</param> /// <param name="timeout">The timeout.</param> /// <param name="syncContext">The synchronize context.</param> /// <param name="invokeContext">The invoke context.</param> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> public InvokeAsyncResult( Activity activity, IDictionary <string, object> inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout, SynchronizationContext syncContext, AsyncInvokeContext invokeContext, AsyncCallback callback, object state) : base(callback, state) { if (activity == null) { throw new ArgumentNullException(nameof(activity)); } this.completionWaiter = new AsyncWaitHandle(); syncContext ??= SynchronousSynchronizationContext.Value; this.instance = WorkflowApplication.StartInvoke(activity, inputs, extensions, syncContext, new Action(this.OnInvokeComplete), invokeContext); if (this.completionWaiter.WaitAsync(WaitCompleteCallback, this, timeout)) { var completeSelf = this.OnWorkflowCompletion(); if (completeSelf) { if (this.completionException != null) { throw FxTrace.Exception.AsError(this.completionException); } else { this.Complete(true); } } } }
private void InternalInvokeAsync(IDictionary <string, object> inputs, TimeSpan timeout, object userState) { var context = new AsyncInvokeContext(userState, this); if (userState != null) { AddToPendingInvokes(context); } Exception error = null; var completedSynchronously = false; try { if (invokeCallback == null) { invokeCallback = Fx.ThunkCallback(new AsyncCallback(InvokeCallback)); } context.Operation.OperationStarted(); var result = WorkflowApplication.BeginInvoke(this.workflow, inputs, this.extensions, timeout, SynchronizationContext.Current, context, 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 InternalInvokeAsync(IDictionary <string, object> inputs, TimeSpan timeout, object userState) { AsyncInvokeContext context = new AsyncInvokeContext(userState, this); if (userState != null) { this.AddToPendingInvokes(context); } Exception error = null; bool flag = false; try { if (invokeCallback == null) { invokeCallback = Fx.ThunkCallback(new AsyncCallback(this.InvokeCallback)); } context.Operation.OperationStarted(); IAsyncResult result = System.Activities.WorkflowApplication.BeginInvoke(this.workflow, inputs, this.extensions, timeout, SynchronizationContext.Current, context, invokeCallback, context); if (result.CompletedSynchronously) { context.Outputs = this.EndInvoke(result); flag = true; } } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } error = exception2; } if ((error != null) || flag) { this.PostInvokeCompletedAndRemove(context, error); } }
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; }