Exemple #1
0
        internal override void Run(Task task, bool canInlineContinuationTask)
        {
            // For the base AwaitTaskContinuation, we allow inlining if our caller allows it
            // and if we're in a "valid location" for it.  See the comments on
            // IsValidLocationForInlining for more about what's valid.  For performance
            // reasons we would like to always inline, but we don't in some cases to avoid
            // running arbitrary amounts of work in suspected "bad locations", like UI threads.
            if (canInlineContinuationTask && IsValidLocationForInlining)
            {
                RunCallback(GetInvokeActionCallback(), m_action, ref Task.t_currentTask); // any exceptions from m_action will be handled by s_callbackRunAction
            }
            else
            {
#if !MONO
                TplEtwProvider etwLog = TplEtwProvider.Log;
                if (etwLog.IsEnabled())
                {
                    m_continuationId = Task.NewId();
                    etwLog.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, m_continuationId);
                }
#endif
                // We couldn't inline, so now we need to schedule it
                ThreadPool.UnsafeQueueCustomWorkItem(this, forceGlobal: false);
            }
        }
        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);
        }
Exemple #3
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);
        }
        private static void PostAction(object state)
        {
            var c = (SynchronizationContextAwaitTaskContinuation)state;

#if !FEATURE_PAL && !FEATURE_CORECLR    // PAL and CoreClr don't support  eventing
            TplEtwProvider etwLog = TplEtwProvider.Log;
            if (etwLog.IsEnabled() && c.m_continuationId != 0)
            {
                c.m_syncContext.Post(s_postCallback, GetActionLogDelegate(c.m_continuationId, c.m_action));
            }
            else
#endif
            {
                c.m_syncContext.Post(s_postCallback, c.m_action); // s_postCallback is manually cached, as the compiler won't in a SecurityCritical method
            }
        }
        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);
     }
 }
Exemple #7
0
 internal sealed override void Run(Task task, bool canInlineContinuationTask)
 {
     // If we're allowed to inline, run the action on this thread.
     if (canInlineContinuationTask &&
         m_syncContext == SynchronizationContext.CurrentNoFlow)
     {
         RunCallback(GetInvokeActionCallback(), m_action, ref Task.t_currentTask);
     }
     // Otherwise, Post the action back to the SynchronizationContext.
     else
     {
         TplEtwProvider etwLog = TplEtwProvider.Log;
         if (etwLog.IsEnabled())
         {
             m_continuationId = Task.NewId();
             etwLog.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, m_continuationId);
         }
         RunCallback(GetPostActionCallback(), this, ref Task.t_currentTask);
     }
     // Any exceptions will be handled by RunCallback.
 }