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.

Task<TResult>::Factory Property

 

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

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

public:
property TaskFactory<TResult>^ Factory {
	static TaskFactory<TResult>^ get();
}

Property Value

Type: System.Threading.Tasks::TaskFactory<TResult>^

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

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

Property

Value

TaskFactory<TResult>::CancellationToken

CancellationToken::None

TaskFactory<TResult>::ContinuationOptions

TaskContinuationOptions::None

TaskFactory<TResult>::CreationOptions

TaskCreationOptions::None

TaskFactory<TResult>::Scheduler

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<TResult>::StartNew method.

System_CAPS_noteNote

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

The following example uses the static Factory property to make three calls to the TaskFactory<TResult>::StartNew method. The first starts a Task<Int32> object, which executes a lambda expression that returns 1. The second starts a Task<Test> object, which executes a lambda expression that instantiates a new Test instance. The third starts a Task<String[]> object, which enumerates the files in the C:\Users\Public\Pictures\Sample Pictures\ directory. (Note that successful execution of the example requires that the directory exist and that it contain files.

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
Silverlight
Available since 5.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show: