TaskContinuationOptions 枚举
定义
为通过使用 ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) 或 ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) 方法创建的任务指定行为。Specifies the behavior for a task that is created by using the ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) or ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) method.
此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。
public enum class TaskContinuationOptions
[System.Flags]
[System.Serializable]
public enum TaskContinuationOptions
type TaskContinuationOptions =
Public Enum 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 Tasks。For 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. 如果前面任务的 CancellationTokenSource 已在一个 由于任务以同步方式执行,因此无需调用诸如 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 属性不是 此选项对多任务延续无效。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. 此选项优先于 ExecuteSynchronously。This option has precedence over ExecuteSynchronously. |