TaskCreationOptions Enum

Specifies options that control the creation and execution of tasks.

public enum TaskCreationOptions : int

Members

None

No special options are specified for the task creation.

0

PreferFairness

Specifies that the task scheduler should be biased towards task fairness over task parallelism. This is the default behavior for the Task Parallel Library (TPL) and is therefore not usually required.

1

LongRunning

Specifies that a task is intended to run for a long time. This allows the Task Parallel Library (TPL) to better manage the scheduling of the task on a thread pool thread. Use this option for computationally intensive, blocking operations.

2

DenyChildAttach

Specifies that the Task.ContinueWith method should not be allowed to create child tasks. If a continuation attempts to create a child task, an exception will be thrown.

4

HideScheduler

Specifies that the task should not be wrapped in a Task object when it is queued. This can be useful when dealing with certain synchronization contexts or custom schedulers.

8

ExtendCancellation

Specifies that cancellation of the task should be extended to any child tasks created by the task. This ensures that if the parent task is cancelled, all its children are also cancelled.

16

CaptureContinuousScheduler

Specifies that the current scheduler should be captured and used for any continuations of the task. This can be useful when tasks are being created and executed within a specific synchronization context.

32

PreferLocation

Specifies that the task should be scheduled on the same thread or processor as the data it operates on. This can improve performance by reducing data movement and cache misses.

64

CreateSynchronousContinuations

Specifies that any continuations of the task should be executed synchronously on the same thread that completed the task. This can be useful for avoiding overhead associated with asynchronous continuations.

128

AttachedToParent

Specifies that the task should be attached to its parent task. When a task is attached to its parent, its completion contributes to the completion of the parent. The parent task will not complete until all of its attached children have completed.

256

ExplicitlyAttached

Specifies that the task is explicitly attached to its parent. This is similar to AttachedToParent, but it requires explicit handling of the parent's completion.

512

LazyCancellation

Specifies that cancellation should only be considered when the task is about to begin its execution. This option defers cancellation checks until the task starts running.

1024

Cancellation_SetAsException

Specifies that if the task is canceled, its status should be set to faulted, and the OperationCanceledException should be thrown. This allows the cancellation to be treated as an exception for fault handling purposes.

2048