TaskCreationOptions 枚举

定义

指定可控制任务的创建和执行的可选行为的标志。Specifies flags that control optional behavior for the creation and execution of tasks.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class TaskCreationOptions
[System.Flags]
[System.Serializable]
public enum TaskCreationOptions
type TaskCreationOptions = 
Public Enum TaskCreationOptions
继承
TaskCreationOptions
属性

字段

AttachedToParent 4

指定将任务附加到任务层次结构中的某个父级。Specifies that a task is attached to a parent in the task hierarchy. 默认情况下,子任务(即由外部任务创建的内部任务)将独立于其父任务执行。By default, a child task (that is, an inner task created by an outer task) executes independently of its parent. 可以使用 AttachedToParent 选项以便将父任务和子任务同步。You can use the AttachedToParent option so that the parent and child tasks are synchronized.

请注意,如果使用 DenyChildAttach 选项配置父任务,则子任务中的 AttachedToParent 选项不起作用,并且子任务将作为分离的子任务执行。Note that if a parent task is configured with the DenyChildAttach option, the AttachedToParent option in the child task has no effect, and the child task will execute as a detached child task.

有关详细信息,请参阅附加和分离的子任务For more information, see Attached and Detached Child Tasks.

DenyChildAttach 8

指定任何尝试作为附加的子任务执行(即,使用 AttachedToParent 选项创建)的子任务都无法附加到父任务,会改成作为分离的子任务执行。Specifies that any child task that attempts to execute as an attached child task (that is, it is created with the AttachedToParent option) will not be able to attach to the parent task and will execute instead as a detached child task. 有关详细信息,请参阅 附加和分离的子任务For more information, see Attached and Detached Child Tasks.

HideScheduler 16

防止环境计划程序被视为已创建任务的当前计划程序。Prevents the ambient scheduler from being seen as the current scheduler in the created task. 这意味着像 StartNew 或 ContinueWith 创建任务的执行操作将被视为 Default 当前计划程序。This means that operations like StartNew or ContinueWith that are performed in the created task will see Default as the current scheduler.

LongRunning 2

指定任务将是长时间运行的、粗粒度的操作,涉及比细化的系统更少、更大的组件。Specifies that a task will be a long-running, coarse-grained operation involving fewer, larger components than fine-grained systems. 它会向 TaskScheduler 提示,过度订阅可能是合理的。It provides a hint to the TaskScheduler that oversubscription may be warranted. 可以通过过度订阅创建比可用硬件线程数更多的线程。Oversubscription lets you create more threads than the available number of hardware threads. 它还将提示任务计划程序:该任务需要附加线程,以使任务不阻塞本地线程池队列中其他线程或工作项的向前推动。It also provides a hint to the task scheduler that an additional thread might be required for the task so that it does not block the forward progress of other threads or work items on the local thread-pool queue.

None 0

指定应使用默认行为。Specifies that the default behavior should be used.

PreferFairness 1

提示 TaskScheduler 以一种尽可能公平的方式安排任务,这意味着较早安排的任务将更可能较早运行,而较晚安排运行的任务将更可能较晚运行。A hint to a TaskScheduler to schedule a task in as fair a manner as possible, meaning that tasks scheduled sooner will be more likely to be run sooner, and tasks scheduled later will be more likely to be run later.

RunContinuationsAsynchronously 64

强制异步执行添加到当前任务的延续任务。Forces continuations added to the current task to be executed asynchronously.

请注意,RunContinuationsAsynchronously 成员在以 .NET Framework 4.6.NET Framework 4.6 开头的 TaskCreationOptions 枚举中可用。Note that the RunContinuationsAsynchronously member is available in the TaskCreationOptions enumeration starting with the .NET Framework 4.6.NET Framework 4.6.

注解

TaskCreationOptions枚举可用于以下方法:The TaskCreationOptions enumeration is used with the following methods:

  • TaskFactory和具有参数creationOptions的构造函数, 以指定任务工厂创建的任务的默认选项。 TaskFactory<TResult>The TaskFactory and TaskFactory<TResult> constructors with a creationOptions parameter, to specify the default options for tasks created by the task factory.

  • Task<TResult>使用Task 参数的和构造函数指定用于自定义任务行为的选项。creationOptionsThe Task and Task<TResult> constructors with a creationOptions parameter, to specify the options used to customize the task's behavior.

  • StartNew使用StartNew 参数的和方法,指定用于自定义任务行为的选项。creationOptionsThe StartNew and StartNew methods with a creationOptions parameter, to specify the options used to customize the task's behavior.

  • FromAsync IAsyncResult使用FromAsync 参数的和方法,以指定用于自定义任务的行为的选项,这些选项用于在指定的完成时执行end方法。creationOptionsThe FromAsync and FromAsync methods with a creationOptions parameter, to specify the options used to customize the behavior of the task that executes an end method when a specified IAsyncResult completes.

  • 带参数的TaskCompletionSource<TResult>构造函数, 用于指定用于自定义基础任务行为的选项。 creationOptionsThe TaskCompletionSource<TResult> constructors with a creationOptions parameter, to specify the options used to customize the behavior of the underlying task.

适用于

另请参阅