Exemplo n.º 1
0
            /// <summary>Invokes MoveNext under the provided context.</summary>
            internal void Run()
            {
                if (m_context != null)
                {
                    try
                    {
                        // Get the callback, lazily initializing it as necessary
                        Action <object> callback = s_invokeMoveNext;
                        if (callback == null)
                        {
                            s_invokeMoveNext = callback = InvokeMoveNext;
                        }

                        if (m_context == null)
                        {
                            callback(m_stateMachine);
                        }
                        else
                        {
                            // Use the context and callback to invoke m_stateMachine.MoveNext.
                            ExecutionContextLightup.Instance.Run(m_context, callback, m_stateMachine);
                        }
                    }
                    finally { if (m_context != null)
                              {
                                  m_context.Dispose();
                              }
                    }
                }
                else
                {
                    m_stateMachine.MoveNext();
                }
            }
Exemplo n.º 2
0
            internal void Run()
            {
                Contract.Assert(m_stateMachine != null, "The state machine must have been set before calling Run.");

                if (m_context != null)
                {
                    try
                    {
                        // Get the callback, lazily initializing it as necessary
                        ContextCallback callback = s_invokeMoveNext;
                        if (callback == null)
                        {
                            s_invokeMoveNext = callback = InvokeMoveNext;
                        }

                        // Use the context and callback to invoke m_stateMachine.MoveNext.
                        ExecutionContext.Run(m_context, callback, m_stateMachine);
                    }
                    finally { m_context.Dispose(); }
                }
                else
                {
                    m_stateMachine.MoveNext();
                }
            }
Exemplo n.º 3
0
 internal void Run()
 {
     if (m_context != null)
     {
         try
         {
             Action <object> action = s_invokeMoveNext;
             if (action == null)
             {
                 action = (s_invokeMoveNext = new Action <object>(InvokeMoveNext));
             }
             if (m_context == null)
             {
                 action.Invoke(m_stateMachine);
             }
             else
             {
                 ExecutionContextLightup.Instance.Run(m_context, action, m_stateMachine);
             }
             return;
         }
         finally
         {
             if (m_context != null)
             {
                 m_context.Dispose();
             }
         }
     }
     m_stateMachine.MoveNext();
 }
            /// <summary>Invokes <see cref="IAsyncStateMachine.MoveNext"/> under the provided context.</summary>
            internal void Run()
            {
                if (_context != null)
                {
                    try
                    {
                        Action <object> action = _invokeMoveNext;
                        if (action == null)
                        {
                            action = (_invokeMoveNext = InvokeMoveNext);
                        }

                        if (_context == null)
                        {
                            action.Invoke(_stateMachine);
                        }
                        else
                        {
                            ExecutionContext.Run(_context, x => action(x), _stateMachine);
                        }

                        return;
                    }
                    finally
                    {
                    }
                }

                _stateMachine.MoveNext();
            }
Exemplo n.º 5
0
 public static void ContinueWith(this IAwaitable self, IAsyncStateMachine state)
 {
     if (self.Status == WaitableStatus.Running)
     {
         state.MoveNext();
     }
 }
Exemplo n.º 6
0
 internal void Start(IAsyncStateMachine stateMachine)
 {
     if (stateMachine == null)
     {
         throw new ArgumentNullException("stateMachine");
     }
     stateMachine.MoveNext();
 }
Exemplo n.º 7
0
 public static Action GetActionForState(this IAsyncStateMachine stateMachine, int state)
 {
     return(() =>
     {
         stateMachine.SetState(state);
         stateMachine.MoveNext();
     });
 }
Exemplo n.º 8
0
 public static void UnsafeContinueWith(this IAwaitable self, IAsyncStateMachine state)
 {
     self.Container.Manager.Enqueue(() =>
     {
         if (self.Status == WaitableStatus.Running)
         {
             state.MoveNext();
         }
     });
 }
Exemplo n.º 9
0
 public void Run()
 {
     if (!scope.IsUnavailable)
     {
         machine.MoveNext();
     }
     else
     {
         scope.OnCompleted(Run);
     }
 }
Exemplo n.º 10
0
        public Task <bool> MoveNext(CancellationToken cancel)
        {
            _current   = new TaskCompletionSource <T>();
            _currentSm = clone(this);
            _currentSm.MoveNext();
            var tcs = new TaskCompletionSource <bool>();

            _current.Task.ContinueWith(_ =>
            {
                tcs.SetResult(true);
            });
            return(tcs.Task);
        }
            /// <summary>Invokes <see cref="IAsyncStateMachine.MoveNext"/> under the provided context.</summary>
            internal void Run()
            {
                if (_context != null)
                {
                    try
                    {
                        Action <object> action = _invokeMoveNext;
                        if (action == null)
                        {
                            action = (_invokeMoveNext = InvokeMoveNext);
                        }

                        if (_context == null)
                        {
                            action.Invoke(_stateMachine);
                        }
                        else
                        {
                            var sync = SynchronizationContext.Current;
                            ExecutionContext.Run(_context,
                                                 x =>
                            {
                                if (sync == null)
                                {
                                    var prevContext = SynchronizationContext.Current;
                                    try
                                    {
                                        SynchronizationContext.SetSynchronizationContext(null);
                                        action(x);
                                    }
                                    finally
                                    {
                                        SynchronizationContext.SetSynchronizationContext(prevContext);
                                    }
                                }
                                else
                                {
                                    sync.Post(y => action(y), x);
                                }
                            }, _stateMachine);
                        }

                        return;
                    }
                    finally
                    {
                    }
                }

                _stateMachine.MoveNext();
            }
Exemplo n.º 12
0
            internal void Run()
            {
                if (_context == null)
                {
                    StateMachine.MoveNext();
                    return;
                }
                var callback = _invokeMoveNext;

                if (callback == null)
                {
                    _invokeMoveNext = callback = InvokeMoveNext;
                }
                ExecutionContext.Run(_context, callback, StateMachine);
            }
Exemplo n.º 13
0
            internal void Run()
            {
                if (m_context == null)
                {
                    m_stateMachine.MoveNext();
                    return;
                }

                try
                {
                    var callback = s_invokeMoveNext;
                    if (callback == null)
                    {
                        s_invokeMoveNext = callback = InvokeMoveNext;
                    }
                    ExecutionContext.Run(m_context, callback, m_stateMachine);
                }
                finally
                {
                    // m_context.Dispose();
                }
            }
Exemplo n.º 14
0
            /// <summary>Invokes <see cref="IAsyncStateMachine.MoveNext"/> under the provided context.</summary>
            internal void Run()
            {
                Debug.Assert(_stateMachine != null, "The state machine must have been set before calling Run.");

                if (_context != null)
                {
                    try
                    {
                        // Get the callback, lazily initializing it as necessary
                        Action<object> callback = _invokeMoveNext;
                        if (callback == null)
                        {
                            _invokeMoveNext = callback = InvokeMoveNext;
                        }

                        if (_context == null)
                        {
                            callback(_stateMachine);
                        }
                        else
                        {
                            // Use the context and callback to invoke _stateMachine.MoveNext.
                            ExecutionContextLightup.Instance.Run(_context, callback, _stateMachine);
                        }
                    }
                    finally
                    {
                        if (_context != null)
                            _context.Dispose();
                    }
                }
                else
                {
                    _stateMachine.MoveNext();
                }
            }
Exemplo n.º 15
0
            internal void Run()
            {
                if (context == null)
                {
                    StateMachine.MoveNext();
                    return;
                }

                try
                {
                    var callback = invokeMoveNext;
                    if (callback == null)
                    {
                        invokeMoveNext = callback = InvokeMoveNext;
                    }
                    ExecutionContext.Run(context, callback, StateMachine);
                }
                finally
                {
#if !NET35
                    context.Dispose();
#endif
                }
            }
Exemplo n.º 16
0
 public void Start(IAsyncStateMachine stateMachine)
 {
     stateMachine.MoveNext();
 }
 public void MoveNextSafe()
 {
     Console.WriteLine("In MoveNextSafe");
     ExecutionContext.Run(_context, state => _stateMachine.MoveNext(), null);
 }
 private void AwaitOnCompleted(INotifyCompletion awaiter, IAsyncStateMachine stateMachine)
 {
     awaiter.OnCompleted(() => stateMachine.MoveNext());
 }
 public void Run()
 {
     StateMachine.MoveNext();
 }
Exemplo n.º 20
0
 public void Start <TStateMachine>(ref TStateMachine stateMachine)
     where TStateMachine : IAsyncStateMachine
 {
     StateMachine = stateMachine; //box state machine straight away
     StateMachine.MoveNext();
 }
Exemplo n.º 21
0
 public void Start <TStateMachine>(ref TStateMachine stateMachine)
     where TStateMachine : IAsyncStateMachine
 {
     StateMachine = stateMachine; //box immediately
     StateMachine.MoveNext();
 }
Exemplo n.º 22
0
 public void Start(ref IAsyncStateMachine stateMachine)
 {
     // do the first bit of work syncronously
     stateMachine.MoveNext();
 }