Task.Factory Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Provides access to factory methods for creating and configuring Task and Task<'TResult> instances.

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

static member Factory : TaskFactory with get

Property Value

Type: System.Threading.Tasks.TaskFactory

A factory object that can create a variety of Task and Task<'TResult> objects.

This property returns a default instance of the TaskFactory class that is identical to the one created by calling the parameterless TaskFactory.TaskFactory() constructor. It has the following property values:










null, or TaskScheduler.Current

The most common use of this property is to create and start a new task in a single call to the TaskFactory.StartNew method.


Starting with the .NET Framework 4.5, the Task.Run method provides the easiest way to create a Task object with default configuration values.

The following example uses the static Factory property to make two calls to the TaskFactory.StartNew method. The first populates an array with the names of files in the user's MyDocuments directory, while the second populates an array with the names of subdirectories of the user's MyDocuments directory. It then calls the TaskFactory.ContinueWhenAll(Task[], Action<Task[]>) method, which displays information about the number of files and directories in the two arrays after the first two tasks have completed execution.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 5.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top