示例#1
0
        // Token: 0x06004053 RID: 16467 RVA: 0x000EFBD4 File Offset: 0x000EDDD4
        internal override void Run(Task completedTask, bool bCanInlineContinuationTask)
        {
            TaskContinuationOptions options = this.m_options;
            bool flag = completedTask.IsRanToCompletion ? ((options & TaskContinuationOptions.NotOnRanToCompletion) == TaskContinuationOptions.None) : (completedTask.IsCanceled ? ((options & TaskContinuationOptions.NotOnCanceled) == TaskContinuationOptions.None) : ((options & TaskContinuationOptions.NotOnFaulted) == TaskContinuationOptions.None));
            Task task = this.m_task;

            if (flag)
            {
                if (!task.IsCanceled && AsyncCausalityTracer.LoggingOn)
                {
                    AsyncCausalityTracer.TraceOperationRelation(CausalityTraceLevel.Important, task.Id, CausalityRelation.AssignDelegate);
                }
                task.m_taskScheduler = this.m_taskScheduler;
                if (bCanInlineContinuationTask && (options & TaskContinuationOptions.ExecuteSynchronously) != TaskContinuationOptions.None)
                {
                    TaskContinuation.InlineIfPossibleOrElseQueue(task, true);
                    return;
                }
                try
                {
                    task.ScheduleAndStart(true);
                    return;
                }
                catch (TaskSchedulerException)
                {
                    return;
                }
            }
            task.InternalCancel(false);
        }
示例#2
0
        // Token: 0x0600405C RID: 16476 RVA: 0x000EFE3C File Offset: 0x000EE03C
        internal sealed override void Run(Task ignored, bool canInlineContinuationTask)
        {
            if (this.m_scheduler == TaskScheduler.Default)
            {
                base.Run(ignored, canInlineContinuationTask);
                return;
            }
            bool flag = canInlineContinuationTask && (TaskScheduler.InternalCurrent == this.m_scheduler || Thread.CurrentThread.IsThreadPoolThread);
            Task task = base.CreateTask(delegate(object state)
            {
                try
                {
                    ((Action)state)();
                }
                catch (Exception exc)
                {
                    AwaitTaskContinuation.ThrowAsyncIfNecessary(exc);
                }
            }, this.m_action, this.m_scheduler);

            if (flag)
            {
                TaskContinuation.InlineIfPossibleOrElseQueue(task, false);
                return;
            }
            try
            {
                task.ScheduleAndStart(false);
            }
            catch (TaskSchedulerException)
            {
            }
        }
示例#3
0
        public static void Rooter()
        {
            Task t = null;

            t.GetDelegateContinuationsForDebugger();
            TaskContinuation tc = null;

            tc.GetDelegateContinuationsForDebugger();
            AsyncMethodBuilderCore.TryGetStateMachineForDebugger(null);
            Task.GetActiveTaskFromId(0);
            return;
        }
示例#4
0
 internal override sealed void Run(Task ignored, bool canInlineContinuationTask)
 {
     if (this.m_scheduler == TaskScheduler.Default)
     {
         base.Run(ignored, canInlineContinuationTask);
     }
     else
     {
         int  num  = !canInlineContinuationTask ? 0 : (TaskScheduler.InternalCurrent == this.m_scheduler ? 1 : (Thread.CurrentThread.IsThreadPoolThread ? 1 : 0));
         Task task = this.CreateTask((Action <object>)(state =>
         {
             try
             {
                 ((Action)state)();
             }
             catch (Exception ex)
             {
                 AwaitTaskContinuation.ThrowAsyncIfNecessary(ex);
             }
         }), (object)this.m_action, this.m_scheduler);
         if (num != 0)
         {
             TaskContinuation.InlineIfPossibleOrElseQueue(task, false);
         }
         else
         {
             try
             {
                 task.ScheduleAndStart(false);
             }
             catch (TaskSchedulerException ex)
             {
             }
         }
     }
 }
示例#5
0
        private void AssignCancellationToken(CancellationToken cancellationToken, Task antecedent, TaskContinuation continuation)
        {
            CancellationToken = cancellationToken;
            try
            {
                cancellationToken.ThrowIfSourceDisposed();
                // If an unstarted task has a valid CancellationToken that gets signalled while the task is still not queued
                // we need to proactively cancel it, because it may never execute to transition itself.
                // The only way to accomplish this is to register a callback on the CT.
                // We exclude Promise tasks from this, because TaskCompletionSource needs to fully control the inner tasks's lifetime (i.e. not allow external cancellations)

                if ((_internalOptions & (InternalTaskOptions.QueuedByRuntime | InternalTaskOptions.PromiseTask | InternalTaskOptions.LazyCancellation)) == 0)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        // Fast path for an already-canceled cancellationToken
                        InternalCancel(false);
                    }
                    else
                    {
                        // Regular path for an uncanceled cancellationToken
                        CancellationTokenRegistration registration;
                        if (antecedent == null)
                        {
                            // if no antecedent was specified, use this task's reference as the cancellation state object
                            registration = cancellationToken.Register(_taskCancelCallback, this);
                        }
                        else
                        {
                            // If an antecedent was specified, pack this task, its antecedent and the TaskContinuation together as a tuple
                            // and use it as the cancellation state object. This will be unpacked in the cancellation callback so that
                            // antecedent.RemoveCancellation(continuation) can be invoked.
                            registration = cancellationToken.Register(_taskCancelCallback, new Tuple <Task, Task, TaskContinuation>(this, antecedent, continuation));
                        }
                        _cancellationRegistration = new StrongBox <CancellationTokenRegistration>(registration);
                    }
                }
            }
            catch (Exception)
            {
                // If we have an exception related to our CancellationToken, then we need to subtract ourselves
                // from our parent before throwing it.
                if (_parent != null &&
                    (CreationOptions & TaskCreationOptions.AttachedToParent) != 0 &&
                    (_parent.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0
                    )
                {
                    _parent.DisregardChild();
                }
                throw;
            }
        }
示例#6
0
        private void AssignCancellationToken(CancellationToken cancellationToken, Task antecedent, TaskContinuation continuation)
        {
            CancellationToken = cancellationToken;
            try
            {
                GC.KeepAlive(cancellationToken.WaitHandle);
                // If an unstarted task has a valid CancellationToken that gets signalled while the task is still not queued
                // we need to proactively cancel it, because it may never execute to transition itself.
                // The only way to accomplish this is to register a callback on the CT.
                // We exclude Promise tasks from this, because TaskCompletionSource needs to fully control the inner tasks's lifetime (i.e. not allow external cancellations)

                if ((_internalOptions & (InternalTaskOptions.QueuedByRuntime | InternalTaskOptions.PromiseTask | InternalTaskOptions.LazyCancellation)) != 0)
                {
                    return;
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    // Fast path for an already-canceled cancellationToken
                    InternalCancel(false);
                }
                else
                {
                    // Regular path for an uncanceled cancellationToken
                    var registration = cancellationToken.Register(_taskCancelCallback, antecedent == null ? (object)this : new Tuple <Task, Task, TaskContinuation>(this, antecedent, continuation));
                    _cancellationRegistration = new StrongBox <CancellationTokenRegistration>(registration);
                }
            }
            catch (Exception)
            {
                // If we have an exception related to our CancellationToken, then we need to subtract ourselves
                // from our parent before throwing it.
                if (_parent != null &&
                    (CreationOptions & TaskCreationOptions.AttachedToParent) != 0 &&
                    (_parent.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0
                    )
                {
                    _parent.DisregardChild();
                }

                throw;
            }
        }
        private void AssignCancellationToken(CancellationToken cancellationToken, Task antecedent, TaskContinuation continuation)
        {
            CancellationToken = cancellationToken;
            try
            {
                cancellationToken.ThrowIfSourceDisposed();
                // If an unstarted task has a valid CancellationToken that gets signalled while the task is still not queued
                // we need to proactively cancel it, because it may never execute to transition itself.
                // The only way to accomplish this is to register a callback on the CT.
                // We exclude Promise tasks from this, because TaskCompletionSource needs to fully control the inner tasks's lifetime (i.e. not allow external cancellations)

                if ((_internalOptions & (InternalTaskOptions.QueuedByRuntime | InternalTaskOptions.PromiseTask | InternalTaskOptions.LazyCancellation)) == 0)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        // Fast path for an already-canceled cancellationToken
                        InternalCancel(false);
                    }
                    else
                    {
                        // Regular path for an uncanceled cancellationToken
                        CancellationTokenRegistration registration;
                        if (antecedent == null)
                        {
                            // if no antecedent was specified, use this task's reference as the cancellation state object
                            registration = cancellationToken.Register(_taskCancelCallback, this);
                        }
                        else
                        {
                            // If an antecedent was specified, pack this task, its antecedent and the TaskContinuation together as a tuple
                            // and use it as the cancellation state object. This will be unpacked in the cancellation callback so that
                            // antecedent.RemoveCancellation(continuation) can be invoked.
                            registration = cancellationToken.Register(_taskCancelCallback, new Tuple<Task, Task, TaskContinuation>(this, antecedent, continuation));
                        }
                        _cancellationRegistration = new StrongBox<CancellationTokenRegistration>(registration);
                    }
                }
            }
            catch (Exception)
            {
                // If we have an exception related to our CancellationToken, then we need to subtract ourselves
                // from our parent before throwing it.
                if ((_parent != null)
                    && ((_creationOptions & TaskCreationOptions.AttachedToParent) != 0)
                    && ((_parent._creationOptions & TaskCreationOptions.DenyChildAttach) == 0)
                )
                {
                    _parent.DisregardChild();
                }
                throw;
            }
        }