コード例 #1
0
        internal static void Start <TStateMachine>(ref TStateMachine stateMachine)
            where TStateMachine : IAsyncStateMachine
        {
            if (stateMachine == null)
            {
                throw new ArgumentNullException("stateMachine");
            }
            Contract.EndContractBlock();

            // Run the MoveNext method within a copy-on-write ExecutionContext scope.
            // This allows us to undo any ExecutionContext changes made in MoveNext,
            // so that they won't "leak" out of the first await.

            Thread currentThread         = Thread.CurrentThread;
            ExecutionContextSwitcher ecs = default(ExecutionContextSwitcher);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                ExecutionContext.EstablishCopyOnWriteScope(ref ecs);
                stateMachine.MoveNext();
            }
            finally
            {
                ecs.Undo();
            }
        }
コード例 #2
0
        internal static void Start <TStateMachine>(ref TStateMachine stateMachine)
            where TStateMachine : IAsyncStateMachine
        {
            // Async state machines are required not to throw, so no need for try/finally here.
            ExecutionContextSwitcher ecs = default(ExecutionContextSwitcher);

            ExecutionContext.EstablishCopyOnWriteScope(ref ecs);
            stateMachine.MoveNext();
            ecs.Undo();
        }
コード例 #3
0
        public void Start <TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
        {
            if (stateMachine == null)
            {
                throw new ArgumentNullException("stateMachine");
            }
            ExecutionContextSwitcher executionContextSwitcher = default(ExecutionContextSwitcher);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                ExecutionContext.EstablishCopyOnWriteScope(ref executionContextSwitcher);
                stateMachine.MoveNext();
            }
            finally
            {
                executionContextSwitcher.Undo();
            }
        }
コード例 #4
0
        public void Start <TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
        {
            if (stateMachine == null) // TStateMachines are generally non-nullable value types, so this check will be elided
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stateMachine);
            }

            // Run the MoveNext method within a copy-on-write ExecutionContext scope.
            // This allows us to undo any ExecutionContext changes made in MoveNext,
            // so that they won't "leak" out of the first await.

            Thread currentThread         = Thread.CurrentThread;
            ExecutionContextSwitcher ecs = default(ExecutionContextSwitcher);

            try
            {
                ExecutionContext.EstablishCopyOnWriteScope(currentThread, ref ecs);
                stateMachine.MoveNext();
            }
            finally
            {
                ecs.Undo(currentThread);
            }
        }