TaskContinuationOptions 列舉

定義

public enum class TaskContinuationOptions
[System.Flags]
[System.Serializable]
public enum TaskContinuationOptions
type TaskContinuationOptions = 
Public Enum TaskContinuationOptions
繼承
TaskContinuationOptions
屬性

欄位

AttachedToParent 4

指定將接續 (如果是子工作) 附加至工作階層中的父代。Specifies that the continuation, if it is a child task, is attached to a parent in the task hierarchy. 只有在接續的前項也是子工作時,該接續才可以是子工作。The continuation can be a child task only if its antecedent is also a child task. 根據預設,子工作 (即外部工作所建立的內部工作) 會在其父代之外單獨執行。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 is, any nested inner task created by this continuation) that is created with the AttachedToParent option and attempts to execute as an attached child task will not be able to attach to the parent task and will execute instead as a detached child task. 如需詳細資訊,請參閱 Attached and Detached Child TasksFor more information, see Attached and Detached Child Tasks.

ExecuteSynchronously 524288

指定應該要同步執行接續工作。Specifies that the continuation task should be executed synchronously. 指定這個選項時,接續會在造成前項工作轉換為最終狀態的同一個執行緒上執行。With this option specified, the continuation runs on the same thread that causes the antecedent task to transition into its final state. 如果建立接續時前項已完成,則接續會在建立接續的執行緒上執行。If the antecedent is already complete when the continuation is created, the continuation will run on the thread that creates the continuation. 如果前項的 CancellationTokenSourcefinally 區塊 (在 Visual Basic 中為Finally ) 中遭處置,則會在該 finally 區塊中執行具有這個選項的接續。If the antecedent's CancellationTokenSource is disposed in a finally block (Finally in Visual Basic), a continuation with this option will run in that finally block. 只有執行時間很短的接續工作才適合以同步方式執行。Only very short-running continuations should be executed synchronously.

因為工作以同步方式執行,所以不需要呼叫方法 (如 Wait()),以確保呼叫執行緒等待工作完成。Because the task executes synchronously, there is no need to call a method such as Wait() to ensure that the calling thread waits for the task to complete.

HideScheduler 16

指定接續透過呼叫 Run(Action)ContinueWith(Action<Task>) 等方法所建立的工作,會將預設排程器 (Default) 視為目前的排程器,而不是這個接續執行依據的排程器。Specifies that tasks created by the continuation by calling methods such as Run(Action) or ContinueWith(Action<Task>) see the default scheduler (Default) rather than the scheduler on which this continuation is running as the current scheduler.

LazyCancellation 32

在接續取消的情況下,防止接續在前項完成之前完成。In the case of continuation cancellation, prevents completion of the continuation until the antecedent has completed.

LongRunning 2

指定接續會是長時間執行的繁複作業。Specifies that a continuation will be a long-running, course-grained operation. 這會提示 TaskScheduler 可能會發生過度訂閱的狀況。It provides a hint to the TaskScheduler that oversubscription may be warranted.

None 0

如果未指定任何接續選項,則指定在執行接續時,應該使用預設行為。When no continuation options are specified, specifies that default behavior should be used when executing a continuation. 當前項工作完成時,接續會以非同步方式執行,而不論前項的最終 Status 屬性值為何。The continuation runs asynchronously when the antecedent task completes, regardless of the antecedent's final Status property value. 如果接續為子工作,則會建立為中斷連結的巢狀工作。It the continuation is a child task, it is created as a detached nested task.

NotOnCanceled 262144

指定當前項工作取消時,不應該排定接續工作。Specifies that the continuation task should not be scheduled if its antecedent was canceled. 如果前項在完成時的 Status 屬性為 Canceled,則取消前項。An antecedent is canceled if its Status property upon completion is Canceled. 這個選項對多工接續而言無效。This option is not valid for multi-task continuations.

NotOnFaulted 131072

指定當前項擲回未處理的例外狀況時,不應該排程接續工作。Specifies that the continuation task should not be scheduled if its antecedent threw an unhandled exception. 如果前項在完成時的 Status 屬性為 Faulted,則擲回未處理的例外狀況。An antecedent throws an unhandled exception if its Status property upon completion is Faulted. 這個選項對多工接續而言無效。This option is not valid for multi-task continuations.

NotOnRanToCompletion 65536

指定當前項執行完成時,不應該排程接續工作。Specifies that the continuation task should not be scheduled if its antecedent ran to completion. 如果前項在完成時的 Status 屬性為 RanToCompletion,則執行到完成。An antecedent runs to completion if its Status property upon completion is RanToCompletion. 這個選項對多工接續而言無效。This option is not valid for multi-task continuations.

OnlyOnCanceled 196608

指定只有在取消接續的前項時,才應該排定接續。Specifies that the continuation should be scheduled only if its antecedent was canceled. 如果前項在完成時的 Status 屬性為 Canceled,則取消前項。An antecedent is canceled if its Status property upon completion is Canceled. 這個選項對多工接續而言無效。This option is not valid for multi-task continuations.

OnlyOnFaulted 327680

指定只有在前項擲回未處理的例外狀況時,才應排程接續工作。Specifies that the continuation task should be scheduled only if its antecedent threw an unhandled exception. 如果前項在完成時的 Status 屬性為 Faulted,則擲回未處理的例外狀況。An antecedent throws an unhandled exception if its Status property upon completion is Faulted.

OnlyOnFaulted 選項可確保前項的 Exception 屬性不是 nullThe OnlyOnFaulted option guarantees that the Exception property in the antecedent is not null. 您可以使用該屬性來攔截例外狀況,並查看是哪一種例外狀況導致工作錯誤。You can use that property to catch the exception and see which exception caused the task to fault. 如果您未存取 Exception 屬性,則會形成未處理的例外狀況。If you do not access the Exception property, the exception is unhandled. 此外,如果您嘗試存取已取消或已發生錯誤之工作的 Result 屬性,將會擲回新的例外狀況。Also, if you attempt to access the Result property of a task that has been canceled or has faulted, a new exception is thrown.

這個選項對多工接續而言無效。This option is not valid for multi-task continuations.

OnlyOnRanToCompletion 393216

指定只有在接續的前項徹底執行後,才應該排定接續。Specifies that the continuation should be scheduled only if its antecedent ran to completion. 如果前項在完成時的 Status 屬性為 RanToCompletion,則執行到完成。An antecedent runs to completion if its Status property upon completion is RanToCompletion. 這個選項對多工接續而言無效。This option is not valid for multi-task continuations.

PreferFairness 1

提示 TaskScheduler 依序排程工作,讓先排程的工作早執行的機率較高,後排程的工作晚執行的機率較高。A hint to a TaskScheduler to schedule task in the order in which they were scheduled, so that tasks scheduled sooner are more likely to run sooner, and tasks scheduled later are more likely to run later.

RunContinuationsAsynchronously 64

指定應該要非同步執行接續工作。Specifies that the continuation task should be run asynchronously. 這個選項優先於 ExecuteSynchronouslyThis option has precedence over ExecuteSynchronously.

適用於