예제 #1
0
        protected void RunCallback(ContextCallback callback, object state, ref Task currentTask)
        {
            Task task = currentTask;

            try
            {
                if (task != null)
                {
                    currentTask = (Task)null;
                }
                if (this.m_capturedContext == null)
                {
                    callback(state);
                }
                else
                {
                    ExecutionContext.Run(this.m_capturedContext, callback, state, true);
                }
            }
            catch (Exception ex)
            {
                AwaitTaskContinuation.ThrowAsyncIfNecessary(ex);
            }
            finally
            {
                if (task != null)
                {
                    currentTask = task;
                }
                if (this.m_capturedContext != null)
                {
                    this.m_capturedContext.Dispose();
                }
            }
        }
예제 #2
0
        private void ExecuteWorkItemHelper()
        {
            TplEtwProvider tplEtwProvider = TplEtwProvider.Log;
            Guid           oldActivityThatWillContinue = Guid.Empty;

            if (tplEtwProvider.TasksSetActivityIds && this.m_continuationId != 0)
            {
                EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(this.m_continuationId), out oldActivityThatWillContinue);
            }
            try
            {
                if (this.m_capturedContext == null)
                {
                    this.m_action();
                }
                else
                {
                    try
                    {
                        ExecutionContext.Run(this.m_capturedContext, AwaitTaskContinuation.GetInvokeActionCallback(), (object)this.m_action, true);
                    }
                    finally
                    {
                        this.m_capturedContext.Dispose();
                    }
                }
            }
            finally
            {
                if (tplEtwProvider.TasksSetActivityIds && this.m_continuationId != 0)
                {
                    EventSource.SetCurrentThreadActivityId(oldActivityThatWillContinue);
                }
            }
        }
예제 #3
0
 internal static void RunOrScheduleAction(Action action, bool allowInlining, ref Task currentTask)
 {
     if (!allowInlining || !AwaitTaskContinuation.IsValidLocationForInlining)
     {
         AwaitTaskContinuation.UnsafeScheduleAction(action, currentTask);
     }
     else
     {
         Task task = currentTask;
         try
         {
             if (task != null)
             {
                 currentTask = (Task)null;
             }
             action();
         }
         catch (Exception ex)
         {
             AwaitTaskContinuation.ThrowAsyncIfNecessary(ex);
         }
         finally
         {
             if (task != null)
             {
                 currentTask = task;
             }
         }
     }
 }
예제 #4
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)
            {
            }
        }
예제 #5
0
        internal static void UnsafeScheduleAction(Action action, Task task)
        {
            AwaitTaskContinuation taskContinuation = new AwaitTaskContinuation(action, false);
            TplEtwProvider        tplEtwProvider   = TplEtwProvider.Log;

            if (tplEtwProvider.IsEnabled() && task != null)
            {
                taskContinuation.m_continuationId = Task.NewId();
                tplEtwProvider.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, taskContinuation.m_continuationId);
            }
            ThreadPool.UnsafeQueueCustomWorkItem((IThreadPoolWorkItem)taskContinuation, false);
        }
예제 #6
0
        internal sealed override void Run(Task task, bool canInlineContinuationTask)
        {
            if (canInlineContinuationTask && this.m_syncContext == SynchronizationContext.CurrentNoFlow)
            {
                base.RunCallback(AwaitTaskContinuation.GetInvokeActionCallback(), this.m_action, ref Task.t_currentTask);
                return;
            }
            TplEtwProvider log = TplEtwProvider.Log;

            if (log.IsEnabled())
            {
                this.m_continuationId = Task.NewId();
                log.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, this.m_continuationId);
            }
            base.RunCallback(SynchronizationContextAwaitTaskContinuation.GetPostActionCallback(), this, ref Task.t_currentTask);
        }
        internal override void Run(Task task, bool canInlineContinuationTask)
        {
            if (canInlineContinuationTask && AwaitTaskContinuation.IsValidLocationForInlining)
            {
                this.RunCallback(AwaitTaskContinuation.GetInvokeActionCallback(), this.m_action, ref Task.t_currentTask);
                return;
            }
            TplEtwProvider log = TplEtwProvider.Log;

            if (log.IsEnabled())
            {
                this.m_continuationId = Task.NewId();
                log.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, this.m_continuationId);
            }
            ThreadPool.UnsafeQueueCustomWorkItem(this, false);
        }
 internal override sealed void Run(Task task, bool canInlineContinuationTask)
 {
     if (canInlineContinuationTask && this.m_syncContext == SynchronizationContext.CurrentNoFlow)
     {
         this.RunCallback(AwaitTaskContinuation.GetInvokeActionCallback(), (object)this.m_action, ref Task.t_currentTask);
     }
     else
     {
         TplEtwProvider tplEtwProvider = TplEtwProvider.Log;
         if (tplEtwProvider.IsEnabled())
         {
             this.m_continuationId = Task.NewId();
             tplEtwProvider.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, this.m_continuationId);
         }
         this.RunCallback(SynchronizationContextAwaitTaskContinuation.GetPostActionCallback(), (object)this, ref Task.t_currentTask);
     }
 }
예제 #9
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)
             {
             }
         }
     }
 }
        private void ExecuteWorkItemHelper()
        {
            TplEtwProvider log   = TplEtwProvider.Log;
            Guid           empty = Guid.Empty;

            if (log.TasksSetActivityIds && this.m_continuationId != 0)
            {
                Guid activityId = TplEtwProvider.CreateGuidForTaskID(this.m_continuationId);
                EventSource.SetCurrentThreadActivityId(activityId, out empty);
            }
            try
            {
                if (this.m_capturedContext == null)
                {
                    this.m_action();
                }
                else
                {
                    try
                    {
                        ExecutionContext.Run(this.m_capturedContext, AwaitTaskContinuation.GetInvokeActionCallback(), this.m_action, true);
                    }
                    finally
                    {
                        this.m_capturedContext.Dispose();
                    }
                }
            }
            finally
            {
                if (log.TasksSetActivityIds && this.m_continuationId != 0)
                {
                    EventSource.SetCurrentThreadActivityId(empty);
                }
            }
        }
예제 #11
0
        internal static void UnsafeScheduleAction(Action action)
        {
            var atc = new AwaitTaskContinuation(action, flowExecutionContext: false);

            ThreadPoolAdapter.QueueWorkItem(atc);
        }
예제 #12
0
        internal static void UnsafeScheduleAction(Action action)
        {
            var atc = new AwaitTaskContinuation(action, /*flowExecutionContext:*/ false);

            ThreadPoolAdapter.QueueWorkItem(atc);
        }