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 開始,TaskCreationOptions 列舉中可以使用 .NET Framework 4.6.NET Framework 4.6 成員。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:

  • TaskFactoryTaskFactory<TResult> 具有 creationOptions 參數的處理常式,以指定工作 factory 所建立之工作的預設選項。The TaskFactory and TaskFactory<TResult> constructors with a creationOptions parameter, to specify the default options for tasks created by the task factory.

  • TaskTask<TResult> 具有 creationOptions 參數的處理常式,以指定用來自訂工作行為的選項。The Task and Task<TResult> constructors with a creationOptions parameter, to specify the options used to customize the task's behavior.

  • 使用 creationOptions 參數的 StartNewStartNew 方法,以指定用來自訂工作行為的選項。The StartNew and StartNew methods with a creationOptions parameter, to specify the options used to customize the task's behavior.

  • 具有 creationOptions 參數的 FromAsyncFromAsync 方法,用來指定在指定的 IAsyncResult 完成時,用來自訂執行 end 方法之工作行為的選項。The 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.

  • 具有 creationOptions 參數的 TaskCompletionSource<TResult> 的函式,用來指定用來自訂基礎工作行為的選項。The TaskCompletionSource<TResult> constructors with a creationOptions parameter, to specify the options used to customize the behavior of the underlying task.

適用於

另請參閱