TaskScheduler.TryExecuteTaskInline(Task, Boolean) 方法

定义

确定是否可以在此调用中同步执行提供的 Task,如果可以,将执行该任务。Determines whether the provided Task can be executed synchronously in this call, and if it can, executes it.

protected:
 abstract bool TryExecuteTaskInline(System::Threading::Tasks::Task ^ task, bool taskWasPreviouslyQueued);
[System.Security.SecurityCritical]
protected abstract bool TryExecuteTaskInline (System.Threading.Tasks.Task task, bool taskWasPreviouslyQueued);
protected abstract bool TryExecuteTaskInline (System.Threading.Tasks.Task task, bool taskWasPreviouslyQueued);
[<System.Security.SecurityCritical>]
abstract member TryExecuteTaskInline : System.Threading.Tasks.Task * bool -> bool
abstract member TryExecuteTaskInline : System.Threading.Tasks.Task * bool -> bool
Protected MustOverride Function TryExecuteTaskInline (task As Task, taskWasPreviouslyQueued As Boolean) As Boolean

参数

task
Task

要执行的 TaskThe Task to be executed.

taskWasPreviouslyQueued
Boolean

一个布尔值,该值指示任务之前是否已排队。A Boolean denoting whether or not task has previously been queued. 如果此参数为 True,则该任务以前可能已排队(已计划);如果为 False,则已知该任务尚未排队,此时将执行此调用,以便以内联方式执行该任务,而不用将其排队。If this parameter is True, then the task may have been previously queued (scheduled); if False, then the task is known not to have been queued, and this call is being made in order to execute the task inline without queuing it.

返回

Boolean

一个布尔值,该值指示是否已以内联方式执行该任务。A Boolean value indicating whether the task was executed inline.

属性

例外

task 参数为 null。The task argument is null.

已执行的 taskThe task was already executed.

注解

派生自的类 TaskScheduler 实现此函数,以支持在启动任务对象等待的线程上内联执行任务。A class derived from TaskScheduler implements this function to support inline execution of a task on a thread that initiates a wait on that task object. "内联执行" 是可选的,并且通过返回 false 可能会拒绝该请求。Inline execution is optional, and the request may be rejected by returning false. 但是,可以内联的任务越多,计划程序的缩放就越好。However, the more tasks that can be inlined, the better the scheduler will scale. 事实上,inlines 太少的计划程序可能容易发生死锁。In fact, a scheduler that inlines too little may be prone to deadlocks. 正确的实现应确保在由计划程序保证的策略下执行的请求可以成功内联。A proper implementation should ensure that a request executing under the policies guaranteed by the scheduler can successfully inline. 例如,如果计划程序使用专用线程来执行任务,则该线程的任何内联请求都应成功。For example, if a scheduler uses a dedicated thread to execute tasks, any inlining requests from that thread should succeed.

如果计划程序决定执行内联执行,则应通过 TryExecuteTask 使用提供的任务对象调用基 TaskScheduler 的方法,传播返回值来执行此操作。If a scheduler decides to perform the inline execution, it should do so by calling to the base TaskScheduler's TryExecuteTask method with the provided task object, propagating the return value. 如果计划器决定遵循内联请求,则它可能还适用于计划程序从其内部数据结构中删除内联的任务。It may also be appropriate for the scheduler to remove an inlined task from its internal data structures if it decides to honor the inlining request. 但请注意,在某些情况下,可能会要求计划程序将以前没有提供给它的任务内联到该 QueueTask 方法。Note, however, that under some circumstances a scheduler may be asked to inline a task that was not previously provided to it with the QueueTask method.

派生计划程序负责确保调用线程适用于其自己的计划和执行策略所涉及的任务。The derived scheduler is responsible for making sure that the calling thread is suitable for executing the given task as far as its own scheduling and execution policies are concerned.

有关详细信息,请参阅 TaskSchedulerFor more information, see TaskScheduler.

适用于

另请参阅