mscorlib(4.0.0.0) API with additions
System.Threading.Tasks Namespace Reference

Classes

class  ConcurrentExclusiveSchedulerPair
 Provides task schedulers that coordinate to execute tasks while ensuring that concurrent tasks may run concurrently and exclusive tasks never do. More...
 
class  Parallel
 Provides support for parallel loops and regions. More...
 
struct  ParallelLoopResult
 Provides completion status on the execution of a T:System.Threading.Tasks.Parallel loop. More...
 
class  ParallelLoopState
 Enables iterations of parallel loops to interact with other iterations. An instance of this class is provided by the T:System.Threading.Tasks.Parallel class to each loop; you can not create instances in your code. More...
 
class  ParallelOptions
 Stores options that configure the operation of methods on the T:System.Threading.Tasks.Parallel class. More...
 
class  Task
 Represents an asynchronous operation that can return a value. More...
 
class  TaskCanceledException
 Represents an exception used to communicate task cancellation. More...
 
class  TaskCompletionSource
 Represents the producer side of a T:System.Threading.Tasks.Task`1 unbound to a delegate, providing access to the consumer side through the P:System.Threading.Tasks.TaskCompletionSource`1.Task property. More...
 
class  TaskExtensions
 Provides a set of static (Shared in Visual Basic) methods for working with specific kinds of T:System.Threading.Tasks.Task instances. More...
 
class  TaskFactory
 Provides support for creating and scheduling T:System.Threading.Tasks.Task`1 objects. More...
 
class  TaskScheduler
 Represents an object that handles the low-level work of queuing tasks onto threads. More...
 
class  TaskSchedulerException
 Represents an exception used to communicate an invalid operation by a T:System.Threading.Tasks.TaskScheduler. More...
 
class  UnobservedTaskExceptionEventArgs
 Provides data for the event that is raised when a faulted T:System.Threading.Tasks.Task's exception goes unobserved. More...
 

Enumerations

enum  AsyncCausalityStatus { Canceled = 2, Completed = 1, Error = 3, Started = 0 }
 
enum  CausalityRelation {
  AssignDelegate, Join, Choice, Cancel,
  Error
}
 
enum  CausalitySynchronousWork { CompletionNotification, ProgressNotification, Execution }
 
enum  CausalityTraceLevel { Required, Important, Verbose }
 
enum  InternalTaskOptions {
  None = 0x0, InternalOptionsMask = 0xFF00, ChildReplica = 0x100, ContinuationTask = 0x200,
  PromiseTask = 0x400, SelfReplicating = 0x800, LazyCancellation = 0x1000, QueuedByRuntime = 0x2000,
  DoNotDispose = 0x4000
}
 
enum  TaskContinuationOptions {
  TaskContinuationOptions.None = 0x0, TaskContinuationOptions.PreferFairness = 0x1, TaskContinuationOptions.LongRunning = 0x2, TaskContinuationOptions.AttachedToParent = 0x4,
  TaskContinuationOptions.DenyChildAttach = 0x8, TaskContinuationOptions.HideScheduler = 0x10, TaskContinuationOptions.LazyCancellation = 0x20, TaskContinuationOptions.RunContinuationsAsynchronously = 0x40,
  TaskContinuationOptions.NotOnRanToCompletion = 0x10000, TaskContinuationOptions.NotOnFaulted = 0x20000, TaskContinuationOptions.NotOnCanceled = 0x40000, TaskContinuationOptions.OnlyOnRanToCompletion = 0x60000,
  TaskContinuationOptions.OnlyOnFaulted = 0x50000, TaskContinuationOptions.OnlyOnCanceled = 0x30000, TaskContinuationOptions.ExecuteSynchronously = 0x80000
}
 Specifies the behavior for a task that is created by using the M:System.Threading.Tasks.Task.ContinueWith(System.Action<System.Threading.Tasks.Task>,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler) or M:System.Threading.Tasks.Task`1.ContinueWith(System.Action<System.Threading.Tasks.Task<`0>>,System.Threading.Tasks.TaskContinuationOptions) method. More...
 
enum  TaskCreationOptions {
  TaskCreationOptions.None = 0x0, TaskCreationOptions.PreferFairness = 0x1, TaskCreationOptions.LongRunning = 0x2, TaskCreationOptions.AttachedToParent = 0x4,
  TaskCreationOptions.DenyChildAttach = 0x8, TaskCreationOptions.HideScheduler = 0x10, TaskCreationOptions.RunContinuationsAsynchronously = 0x40
}
 Specifies flags that control optional behavior for the creation and execution of tasks. More...
 
enum  TaskStatus {
  TaskStatus.Created, TaskStatus.WaitingForActivation, TaskStatus.WaitingToRun, TaskStatus.Running,
  TaskStatus.WaitingForChildrenToComplete, TaskStatus.RanToCompletion, TaskStatus.Canceled, TaskStatus.Faulted
}
 Represents the current stage in the lifecycle of a T:System.Threading.Tasks.Task. More...
 

Enumeration Type Documentation

◆ TaskContinuationOptions

Specifies the behavior for a task that is created by using the M:System.Threading.Tasks.Task.ContinueWith(System.Action<System.Threading.Tasks.Task>,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler) or M:System.Threading.Tasks.Task`1.ContinueWith(System.Action<System.Threading.Tasks.Task<`0>>,System.Threading.Tasks.TaskContinuationOptions) method.

Enumerator
None 

When no continuation options are specified, specifies that default behavior should be used when executing a continuation. The continuation runs asynchronously when the antecedent task completes, regardless of the antecedent's final P:System.Threading.Tasks.Task.Status property value. It the continuation is a child task, it is created as a detached nested task.

PreferFairness 

A hint to a T:System.Threading.Tasks.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.

LongRunning 

Specifies that a continuation will be a long-running, course-grained operation. It provides a hint to the T:System.Threading.Tasks.TaskScheduler that oversubscription may be warranted.

AttachedToParent 

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. You can use the F:System.Threading.Tasks.TaskContinuationOptions.AttachedToParent option so that the parent and child tasks are synchronized. Note that if a parent task is configured with the F:System.Threading.Tasks.TaskCreationOptions.DenyChildAttach option, the F:System.Threading.Tasks.TaskCreationOptions.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 

Specifies that any child task (that is, any nested inner task created by this continuation) that is created with the F:System.Threading.Tasks.TaskCreationOptions.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. For more information, see Attached and Detached Child Tasks.

HideScheduler 

Specifies that tasks created by the continuation by calling methods such as M:System.Threading.Tasks.Task.Run(System.Action) or M:System.Threading.Tasks.Task.ContinueWith(System.Action<System.Threading.Tasks.Task>) see the default scheduler (P:System.Threading.Tasks.TaskScheduler.Default) rather than the scheduler on which this continuation is running as the current scheduler.

LazyCancellation 

In the case of continuation cancellation, prevents completion of the continuation until the antecedent has completed.

RunContinuationsAsynchronously 

Specifies that the continuation task should be run asynchronously. This option has precedence over F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously.

NotOnRanToCompletion 

Specifies that the continuation task should not be scheduled if its antecedent ran to completion. An antecedent runs to completion if its P:System.Threading.Tasks.Task.Status property upon completion is F:System.Threading.Tasks.TaskStatus.RanToCompletion. This option is not valid for multi-task continuations.

NotOnFaulted 

Specifies that the continuation task should not be scheduled if its antecedent threw an unhandled exception. An antecedent throws an unhandled exception if its P:System.Threading.Tasks.Task.Status property upon completion is F:System.Threading.Tasks.TaskStatus.Faulted. This option is not valid for multi-task continuations.

NotOnCanceled 

Specifies that the continuation task should not be scheduled if its antecedent was canceled. An antecedent is canceled if its P:System.Threading.Tasks.Task.Status property upon completion is F:System.Threading.Tasks.TaskStatus.Canceled. This option is not valid for multi-task continuations.

OnlyOnRanToCompletion 

Specifies that the continuation should be scheduled only if its antecedent ran to completion. An antecedent runs to completion if its P:System.Threading.Tasks.Task.Status property upon completion is F:System.Threading.Tasks.TaskStatus.RanToCompletion. This option is not valid for multi-task continuations.

OnlyOnFaulted 

Specifies that the continuation task should be scheduled only if its antecedent threw an unhandled exception. An antecedent throws an unhandled exception if its P:System.Threading.Tasks.Task.Status property upon completion is F:System.Threading.Tasks.TaskStatus.Faulted. The F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted option guarantees that the P:System.Threading.Tasks.Task.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. If you do not access the P:System.Threading.Tasks.Task.Exception property, the exception is unhandled. Also, if you attempt to access the P:System.Threading.Tasks.Task`1.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.

OnlyOnCanceled 

Specifies that the continuation should be scheduled only if its antecedent was canceled. An antecedent is canceled if its P:System.Threading.Tasks.Task.Status property upon completion is F:System.Threading.Tasks.TaskStatus.Canceled. This option is not valid for multi-task continuations.

ExecuteSynchronously 

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. If the antecedent's T:System.Threading.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. Because the task executes synchronously, there is no need to call a method such as M:System.Threading.Tasks.Task.Wait to ensure that the calling thread waits for the task to complete.

Definition at line 7 of file TaskContinuationOptions.cs.

◆ TaskCreationOptions

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

Enumerator
None 

Specifies that the default behavior should be used.

PreferFairness 

A hint to a T:System.Threading.Tasks.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.

LongRunning 

Specifies 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 T:System.Threading.Tasks.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.

AttachedToParent 

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. You can use the F:System.Threading.Tasks.TaskContinuationOptions.AttachedToParent option so that the parent and child tasks are synchronized. Note that if a parent task is configured with the F:System.Threading.Tasks.TaskCreationOptions.DenyChildAttach option, the F:System.Threading.Tasks.TaskCreationOptions.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 

Specifies that any child task that attempts to execute as an attached child task (that is, it is created with the F:System.Threading.Tasks.TaskCreationOptions.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 

Prevents 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 P:System.Threading.Tasks.TaskScheduler.Default as the current scheduler.

RunContinuationsAsynchronously 

Forces continuations added to the current task to be executed asynchronously. Note that the F:System.Threading.Tasks.TaskCreationOptions.RunContinuationsAsynchronously member is available in the T:System.Threading.Tasks.TaskCreationOptions enumeration starting with the .NET Framework 4.6.

Definition at line 7 of file TaskCreationOptions.cs.

◆ TaskStatus

Represents the current stage in the lifecycle of a T:System.Threading.Tasks.Task.

Enumerator
Created 

The task has been initialized but has not yet been scheduled.

WaitingForActivation 

The task is waiting to be activated and scheduled internally by the .NET Framework infrastructure.

WaitingToRun 

The task has been scheduled for execution but has not yet begun executing.

Running 

The task is running but has not yet completed.

WaitingForChildrenToComplete 

The task has finished executing and is implicitly waiting for attached child tasks to complete.

RanToCompletion 

The task completed execution successfully.

Canceled 

The task acknowledged cancellation by throwing an OperationCanceledException with its own CancellationToken while the token was in signaled state, or the task's CancellationToken was already signaled before the task started executing. For more information, see Task Cancellation.

Faulted 

The task completed due to an unhandled exception.

Definition at line 5 of file TaskStatus.cs.