当前位置: 首页>>代码示例>>C#>>正文


C# Task.FireTaskScheduledIfNeeded方法代码示例

本文整理汇总了C#中Task.FireTaskScheduledIfNeeded方法的典型用法代码示例。如果您正苦于以下问题:C# Task.FireTaskScheduledIfNeeded方法的具体用法?C# Task.FireTaskScheduledIfNeeded怎么用?C# Task.FireTaskScheduledIfNeeded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Task的用法示例。


在下文中一共展示了Task.FireTaskScheduledIfNeeded方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryRunInline

        internal bool TryRunInline(Task task, bool taskWasPreviouslyQueued)
        {
            // Do not inline unstarted tasks (i.e., task.ExecutingTaskScheduler == null).
            // Do not inline TaskCompletionSource-style (a.k.a. "promise") tasks.
            // No need to attempt inlining if the task body was already run (i.e. either TASK_STATE_DELEGATE_INVOKED or TASK_STATE_CANCELED bits set)
            TaskScheduler ets = task.ExecutingTaskScheduler;
            
            // Delegate cross-scheduler inlining requests to target scheduler
            if(ets != this && ets !=null) return ets.TryRunInline(task, taskWasPreviouslyQueued);

            StackGuard currentStackGuard;
            if( (ets == null) ||
                (task.m_action == null) ||
                task.IsDelegateInvoked || 
                task.IsCanceled ||
                (currentStackGuard = Task.CurrentStackGuard).TryBeginInliningScope() == false)
            {
                return false;
            }

            // Task class will still call into TaskScheduler.TryRunInline rather than TryExecuteTaskInline() so that 
            // 1) we can adjust the return code from TryExecuteTaskInline in case a buggy custom scheduler lies to us
            // 2) we maintain a mechanism for the TLS lookup optimization that we used to have for the ConcRT scheduler (will potentially introduce the same for TP)
            bool bInlined = false;
            try
            {
                task.FireTaskScheduledIfNeeded(this);
                bInlined = TryExecuteTaskInline(task, taskWasPreviouslyQueued);
            }
            finally
            {
                currentStackGuard.EndInliningScope();
            }

            // If the custom scheduler returned true, we should either have the TASK_STATE_DELEGATE_INVOKED or TASK_STATE_CANCELED bit set
            // Otherwise the scheduler is buggy
            if (bInlined && !(task.IsDelegateInvoked || task.IsCanceled)) 
            {
                throw new InvalidOperationException(Environment.GetResourceString("TaskScheduler_InconsistentStateAfterTryExecuteTaskInline"));
            }

            return bInlined;
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:43,代码来源:TaskScheduler.cs

示例2: InternalQueueTask

        internal void InternalQueueTask(Task task)
        {
            Contract.Requires(task != null);

            task.FireTaskScheduledIfNeeded(this);

            this.QueueTask(task);
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:8,代码来源:TaskScheduler.cs

示例3: InternalQueueTask

        internal void InternalQueueTask(Task task)
        {
            Contract.Requires(task != null);

#if !FEATURE_PAL && !FEATURE_CORECLR
            task.FireTaskScheduledIfNeeded(this);
#endif
            this.QueueTask(task);
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:9,代码来源:TaskScheduler.cs


注:本文中的Task.FireTaskScheduledIfNeeded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。