/// <summary>指定的 awaiter 完成时,安排状态机,以继续下一操作。</summary>
 /// <typeparam name="TAwaiter"></typeparam>
 /// <typeparam name="TStateMachine"></typeparam>
 /// <param name="awaiter"></param>
 /// <param name="stateMachine"></param>
 public void AwaitOnCompleted <TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
 {
     try
     {
         Action completionAction = m_coreState.GetCompletionAction <AsyncVoidMethodBuilder, TStateMachine>(ref this, ref stateMachine);
         awaiter.OnCompleted(completionAction);
     }
     catch (Exception exception)
     {
         AsyncServices.ThrowAsync(exception, null);
     }
 }
Esempio n. 2
0
 /// <summary>
 ///     Schedules the state machine to proceed to the next action when the specified awaiter completes.
 /// </summary>
 /// <param name="awaiter">The awaiter.</param>
 /// <param name="stateMachine">The state machine.</param>
 /// <typeparam name="TAwaiter">The type of the awaiter.</typeparam>
 /// <typeparam name="TStateMachine">The type of the state machine.</typeparam>
 public void TrueAwaitOnCompleted(INotifyCompletion awaiter, IAsyncStateMachine stateMachine)
 {
     try
     {
         Action completionAction = m_coreState.GetCompletionAction(this, stateMachine);
         awaiter.OnCompleted(completionAction);
     }
     catch (Exception ex)
     {
         AsyncMethodBuilderCore.ThrowAsync(ex);
     }
 }
Esempio n. 3
0
 /// <summary>
 ///     Schedules the specified state machine to be pushed forward when the specified awaiter completes.
 /// </summary>
 /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
 /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
 /// <param name="awaiter">The awaiter.</param>
 /// <param name="stateMachine">The state machine.</param>
 public void AwaitOnCompleted <TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
     where TAwaiter : INotifyCompletion
     where TStateMachine : IAsyncStateMachine
 {
     try
     {
         var completionAction = _coreState.GetCompletionAction(ref this, ref stateMachine);
         awaiter.OnCompleted(completionAction);
     }
     catch (Exception ex)
     {
         AsyncMethodBuilderCore.ThrowOnContext(ex, null);
     }
 }
 /// <summary>
 /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
 /// </summary>
 /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
 /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
 /// <param name="awaiter">The awaiter.</param>
 /// <param name="stateMachine">The state machine.</param>
 public void AwaitOnCompleted <TAwaiter, TStateMachine>(
     ref TAwaiter awaiter, ref TStateMachine stateMachine)
     where TAwaiter : INotifyCompletion
     where TStateMachine : IAsyncStateMachine
 {
     try
     {
         var continuation = m_coreState.GetCompletionAction(ref this, ref stateMachine);
         awaiter.OnCompleted(continuation);
     }
     catch (Exception e)
     {
         AsyncServices.ThrowAsync(e, targetContext: null);
     }
 }
 /// <summary>
 /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
 /// </summary>
 /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
 /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
 /// <param name="awaiter">The awaiter.</param>
 /// <param name="stateMachine">The state machine.</param>
 public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
     where TAwaiter : INotifyCompletion
     where TStateMachine : IAsyncStateMachine
 {
     try
     {
         var continuation = _coreState.GetCompletionAction(ref this, ref stateMachine);
         Debug.Assert(continuation != null, "GetCompletionAction should always return a valid action.");
         awaiter.OnCompleted(continuation);
     }
     catch (Exception e)
     {
         AsyncServices.ThrowAsync(e, targetContext: null);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
 /// </summary>
 /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
 /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
 /// <param name="awaiter">The awaiter.</param>
 /// <param name="stateMachine">The state machine.</param>
 public void AwaitUnsafeOnCompleted <TAwaiter, TStateMachine>(
     ref TAwaiter awaiter, ref TStateMachine stateMachine)
     where TAwaiter : ICriticalNotifyCompletion
     where TStateMachine : IAsyncStateMachine
 {
     AsyncMethodBuilderCore.CallUnsafeOnCompleted(
         AsyncMethodBuilderCore.GetCompletionAction(ref m_moveNextAction, ref stateMachine, this.GetTaskIfDebuggingEnabled()),
         ref awaiter);
 }
 /// <summary>
 /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
 /// </summary>
 /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
 /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
 /// <param name="awaiter">The awaiter.</param>
 /// <param name="stateMachine">The state machine.</param>
 public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
     where TAwaiter : INotifyCompletion
     where TStateMachine : IAsyncStateMachine
 {
     try
     {
         var continuation = _coreState.GetCompletionAction(ref this, ref stateMachine);
         Debug.Assert(continuation != null, "GetCompletionAction should always return a valid action.");
         awaiter.OnCompleted(continuation);
     }
     catch (Exception exc)
     {
         // Prevent exceptions from leaking to the call site, which could
         // then allow multiple flows of execution through the same async method
         // if the awaiter had already scheduled the continuation by the time
         // the exception was thrown.  We propagate the exception on the
         // ThreadPool because we can trust it to not throw, unlike
         // if we were to go to a user-supplied SynchronizationContext,
         // whose Post method could easily throw.
         AsyncServices.ThrowAsync(exc, targetContext: null);
     }
 }