TaskScheduler.TryExecuteTask(Task) 方法

定义

尝试在此计划程序上执行提供的 TaskAttempts to execute the provided Task on this scheduler.

protected:
 bool TryExecuteTask(System::Threading::Tasks::Task ^ task);
[System.Security.SecurityCritical]
protected bool TryExecuteTask (System.Threading.Tasks.Task task);
protected bool TryExecuteTask (System.Threading.Tasks.Task task);
[<System.Security.SecurityCritical>]
member this.TryExecuteTask : System.Threading.Tasks.Task -> bool
member this.TryExecuteTask : System.Threading.Tasks.Task -> bool
Protected Function TryExecuteTask (task As Task) As Boolean

参数

task
Task

要执行的 Task 对象。A Task object to be executed.

返回

Boolean

一个布尔值,如果成功执行了 task,则该值为 true;如果未成功执行,则该值为 false。A Boolean that is true if task was successfully executed, false if it was not. 执行失败的常见原因是,该任务先前已经执行或者位于正在由另一个线程执行的进程中。A common reason for execution failure is that the task had previously been executed or is in the process of being executed by another thread.

属性

例外

task 与此计划程序无关联。The task is not associated with this scheduler.

注解

计划程序实现与 Task 通过 QueueTask 方法或方法执行的实例一起提供 TryExecuteTaskInlineScheduler implementations are provided with Task instances to be executed through either the QueueTask method or the TryExecuteTaskInline method. 当计划程序认为合适运行提供的任务时, TryExecuteTask 应使用此方法。When the scheduler deems it appropriate to run the provided task, TryExecuteTask should be used to do so. TryExecuteTask 处理执行任务的所有方面,包括操作调用、异常处理、状态管理和生命周期控制。TryExecuteTask handles all aspects of executing a task, including action invocation, exception handling, state management, and lifecycle control.

TryExecuteTask 必须仅用于 .NET Framework 基础结构向此计划程序提供的任务。TryExecuteTask must only be used for tasks provided to this scheduler by the .NET Framework infrastructure. 不应使用它来执行通过自定义机制获得的任意任务。It should not be used to execute arbitrary tasks obtained through custom mechanisms.

适用于

另请参阅