TaskCreationOptions Enumeration

Specifies flags that control optional behavior for the creation and execution of tasks.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Threading.Tasks
Assemblies:   mscorlib (in mscorlib.dll)
  System.Threading.Tasks (in System.Threading.Tasks.dll)

[SerializableAttribute]
[FlagsAttribute]
public enum TaskCreationOptions

Member nameDescription
Supported by Portable Class LibraryAttachedToParentSpecifies 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. You can use the TaskContinuationOptions.AttachedToParent option so that the parent and child tasks are synchronized. 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.
DenyChildAttachSpecifies 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.
HideSchedulerPrevents the ambient scheduler from being seen as the current scheduler in the created task. This means that operations like StartNew or ContinueWith that are performed in the created task will see Default as the current scheduler.
Supported by Portable Class LibraryLongRunningSpecifies that a task will be a long-running, coarse-grained operation involving fewer, larger components than fine-grained systems. 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.
Supported by Portable Class LibraryNoneSpecifies that the default behavior should be used.
Supported by Portable Class LibraryPreferFairnessA 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.
RunContinuationsAsynchronouslyForces continuations added to the current task to be executed asynchronously.

The TaskCreationOptions enumeration is used with the following methods:

  • The TaskFactory and TaskFactory<TResult> constructors with a creationOptions parameter, to specify the default options for tasks created by the task factory.

  • The Task and Task<TResult> constructors with a creationOptions parameter, to specify the options used to customize the task's behavior.

  • The StartNew and StartNew methods with a creationOptions parameter, to specify the options used to customize the task's behavior.

  • 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.

  • The TaskCompletionSource<TResult> constructors with a creationOptions parameter, to specify the options used to customize the behavior of the underlying task.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft