Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TaskFactory Class

Provides support for creating and scheduling Task objects.

System.Object
  System.Threading.Tasks.TaskFactory

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

[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, 
	ExternalThreading = true)]
public class TaskFactory

The TaskFactory type exposes the following members.

  NameDescription
Public methodTaskFactory()Initializes a new instance of the TaskFactory class with the default configuration.
Public methodTaskFactory(CancellationToken)Initializes a new instance of the TaskFactory class with the specified configuration.
Public methodTaskFactory(TaskScheduler)Initializes a new instance of the TaskFactory class with the specified configuration.
Public methodTaskFactory(TaskCreationOptions, TaskContinuationOptions)Initializes a new instance of the TaskFactory class with the specified configuration.
Public methodTaskFactory(CancellationToken, TaskCreationOptions, TaskContinuationOptions, TaskScheduler)Initializes a new instance of the TaskFactory class with the specified configuration.
Top

  NameDescription
Public propertyCancellationTokenGets the default cancellation token for this task factory.
Public propertyContinuationOptionsGets the default task continuation options for this task factory.
Public propertyCreationOptionsGets the default task creation options for this task factory.
Public propertySchedulerGets the default task scheduler for this task factory.
Top

  NameDescription
Public methodContinueWhenAll(Task[], Action<Task[]>)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll(Task[], Action<Task[]>, CancellationToken)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll(Task[], Action<Task[]>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll(Task[], Action<Task[]>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TResult>(Task[], Func<Task[], TResult>)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TResult>(Task[], Func<Task[], TResult>, CancellationToken)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TResult>(Task[], Func<Task[], TResult>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>, CancellationToken)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TResult>(Task[], Func<Task[], TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[], TResult>)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[], TResult>, CancellationToken)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[], TResult>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[], TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of a set of provided tasks.
Public methodContinueWhenAny(Task[], Action<Task>)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny(Task[], Action<Task>, CancellationToken)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny(Task[], Action<Task>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny(Task[], Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TResult>(Task[], Func<Task, TResult>)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TResult>(Task[], Func<Task, TResult>, CancellationToken)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TResult>(Task[], Func<Task, TResult>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TResult>(Task[], Func<Task, TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>, TResult>)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>, TResult>, CancellationToken)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>, TResult>, TaskContinuationOptions)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>, TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)Creates a continuation task that will be started upon the completion of any task in the provided set.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFromAsync(IAsyncResult, Action<IAsyncResult>)Creates a task that executes an end method action when a specified IAsyncResult completes.
Public methodFromAsync(Func<AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync(IAsyncResult, Action<IAsyncResult>, TaskCreationOptions)Creates a task that executes an end method action when a specified IAsyncResult completes.
Public methodFromAsync(Func<AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync(IAsyncResult, Action<IAsyncResult>, TaskCreationOptions, TaskScheduler)Creates a task that executes an end method action when a specified IAsyncResult completes.
Public methodFromAsync<TResult>(IAsyncResult, Func<IAsyncResult, TResult>)Creates a task that executes an end method function when a specified IAsyncResult completes.
Public methodFromAsync<TResult>(Func<AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TResult>(IAsyncResult, Func<IAsyncResult, TResult>, TaskCreationOptions)Creates a task that executes an end method function when a specified IAsyncResult completes.
Public methodFromAsync<TResult>(Func<AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1>(Func<TArg1, AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, TArg1, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TResult>(IAsyncResult, Func<IAsyncResult, TResult>, TaskCreationOptions, TaskScheduler)Creates a TaskFactory<TResult> that executes an end method function when a specified IAsyncResult completes.
Public methodFromAsync<TArg1>(Func<TArg1, AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, TArg1, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TResult>(Func<TArg1, AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, TArg1, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TResult>(Func<TArg1, AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, TArg1, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2>(Func<TArg1, TArg2, AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, TArg1, TArg2, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2>(Func<TArg1, TArg2, AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, TArg1, TArg2, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2, TResult>(Func<TArg1, TArg2, AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, TArg1, TArg2, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2, TResult>(Func<TArg1, TArg2, AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, TArg1, TArg2, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2, TArg3>(Func<TArg1, TArg2, TArg3, AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, TArg1, TArg2, TArg3, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2, TArg3>(Func<TArg1, TArg2, TArg3, AsyncCallback, Object, IAsyncResult>, Action<IAsyncResult>, TArg1, TArg2, TArg3, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2, TArg3, TResult>(Func<TArg1, TArg2, TArg3, AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, TArg1, TArg2, TArg3, Object)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodFromAsync<TArg1, TArg2, TArg3, TResult>(Func<TArg1, TArg2, TArg3, AsyncCallback, Object, IAsyncResult>, Func<IAsyncResult, TResult>, TArg1, TArg2, TArg3, Object, TaskCreationOptions)Creates a task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model (APM).
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStartNew(Action)Creates and starts a task.
Public methodStartNew(Action, CancellationToken)Creates and starts a task.
Public methodStartNew(Action, TaskCreationOptions)Creates and starts a task.
Public methodStartNew(Action<Object>, Object)Creates and starts a task.
Public methodStartNew(Action<Object>, Object, CancellationToken)Creates and starts a task.
Public methodStartNew(Action<Object>, Object, TaskCreationOptions)Creates and starts a task.
Public methodStartNew(Action, CancellationToken, TaskCreationOptions, TaskScheduler)Creates and starts a task.
Public methodStartNew(Action<Object>, Object, CancellationToken, TaskCreationOptions, TaskScheduler)Creates and starts a task.
Public methodStartNew<TResult>(Func<TResult>)Creates and starts a task.
Public methodStartNew<TResult>(Func<TResult>, CancellationToken)Creates and starts a task.
Public methodStartNew<TResult>(Func<TResult>, TaskCreationOptions)Creates and starts a task.
Public methodStartNew<TResult>(Func<Object, TResult>, Object)Creates and starts a task.
Public methodStartNew<TResult>(Func<Object, TResult>, Object, CancellationToken)Creates and starts a task.
Public methodStartNew<TResult>(Func<Object, TResult>, Object, TaskCreationOptions)Creates and starts a task.
Public methodStartNew<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions, TaskScheduler)Creates and starts a task.
Public methodStartNew<TResult>(Func<Object, TResult>, Object, CancellationToken, TaskCreationOptions, TaskScheduler)Creates and starts a task.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The TaskFactory class encodes some common Task patterns into methods that pick up default settings, which are configurable through its constructors. A default instance of TaskFactory is available through the Factory property.

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

All public and protected members of TaskFactory are thread-safe and may be used concurrently from multiple threads.

Community Additions

Show:
© 2014 Microsoft