TaskFactory Constructors

Definition

Initializes a new instance of the TaskFactory class.

Overloads

TaskFactory()

Initializes a TaskFactory instance with the default configuration.

TaskFactory(CancellationToken)

Initializes a TaskFactory instance with the specified configuration.

TaskFactory(TaskScheduler)

Initializes a TaskFactory instance with the specified configuration.

TaskFactory(TaskCreationOptions, TaskContinuationOptions)

Initializes a TaskFactory instance with the specified configuration.

TaskFactory(CancellationToken, TaskCreationOptions, TaskContinuationOptions, TaskScheduler)

Initializes a TaskFactory instance with the specified configuration.

TaskFactory()

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Initializes a TaskFactory instance with the default configuration.

C#
public TaskFactory();

Remarks

This constructor creates a TaskFactory instance with a default configuration. The TaskCreationOptions property is initialized to None, the TaskContinuationOptions property is initialized to None, and the TaskScheduler property is initialized to the current scheduler (see Current).

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

TaskFactory(CancellationToken)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Initializes a TaskFactory instance with the specified configuration.

C#
public TaskFactory(System.Threading.CancellationToken cancellationToken);

Parameters

cancellationToken
CancellationToken

The CancellationToken that will be assigned to tasks created by this TaskFactory unless another CancellationToken is explicitly specified while calling the factory methods.

Remarks

This constructor creates a TaskFactory instance with a default configuration. The TaskCreationOptions property is initialized to None, the TaskContinuationOptions property is initialized to None, and the TaskScheduler property is initialized to the current scheduler (see Current).

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

TaskFactory(TaskScheduler)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Initializes a TaskFactory instance with the specified configuration.

C#
public TaskFactory(System.Threading.Tasks.TaskScheduler scheduler);
C#
public TaskFactory(System.Threading.Tasks.TaskScheduler? scheduler);

Parameters

scheduler
TaskScheduler

The TaskScheduler to use to schedule any tasks created with this TaskFactory. A null value indicates that the current TaskScheduler should be used.

Remarks

With this constructor, the TaskCreationOptions property is initialized to None, the TaskContinuationOptions property is initialized to None, and the TaskScheduler property is initialized to scheduler, unless it's null, in which case the property is initialized to the current scheduler (see Current).

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

TaskFactory(TaskCreationOptions, TaskContinuationOptions)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Initializes a TaskFactory instance with the specified configuration.

C#
public TaskFactory(System.Threading.Tasks.TaskCreationOptions creationOptions, System.Threading.Tasks.TaskContinuationOptions continuationOptions);

Parameters

creationOptions
TaskCreationOptions

The default TaskCreationOptions to use when creating tasks with this TaskFactory.

continuationOptions
TaskContinuationOptions

The default TaskContinuationOptions to use when creating continuation tasks with this TaskFactory.

Exceptions

The creationOptions argument specifies an invalid TaskCreationOptions value. For more information, see the Remarks for FromAsync(Func<AsyncCallback,Object,IAsyncResult>, Action<IAsyncResult>, Object, TaskCreationOptions).

-or-

The continuationOptions argument specifies an invalid value.

Remarks

With this constructor, the TaskCreationOptions property is initialized to creationOptions, the TaskContinuationOptions property is initialized to continuationOptions, and the TaskScheduler property is initialized to the current scheduler (see Current).

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

TaskFactory(CancellationToken, TaskCreationOptions, TaskContinuationOptions, TaskScheduler)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Initializes a TaskFactory instance with the specified configuration.

C#
public TaskFactory(System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
C#
public TaskFactory(System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler? scheduler);

Parameters

cancellationToken
CancellationToken

The default CancellationToken that will be assigned to tasks created by this TaskFactory unless another CancellationToken is explicitly specified while calling the factory methods.

creationOptions
TaskCreationOptions

The default TaskCreationOptions to use when creating tasks with this TaskFactory.

continuationOptions
TaskContinuationOptions

The default TaskContinuationOptions to use when creating continuation tasks with this TaskFactory.

scheduler
TaskScheduler

The default TaskScheduler to use to schedule any Tasks created with this TaskFactory. A null value indicates that TaskScheduler.Current should be used.

Exceptions

The creationOptions argument specifies an invalid TaskCreationOptions value. For more information, see the Remarks for FromAsync(Func<AsyncCallback,Object,IAsyncResult>, Action<IAsyncResult>, Object, TaskCreationOptions).

-or-

The continuationOptions argument specifies an invalid value.

Remarks

With this constructor, the TaskCreationOptions property is initialized to creationOptions, the TaskContinuationOptions property is initialized to continuationOptions, and the TaskScheduler property is initialized to scheduler, unless it's null, in which case the property is initialized to the current scheduler (see Current).

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0