TaskFactory<TResult>.StartNew Method

Definition

Creates and starts a task.

Overloads

StartNew(Func<Object,TResult>, Object, CancellationToken)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object,TResult> function, object state, System.Threading.CancellationToken cancellationToken);
C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object?,TResult> function, object? state, System.Threading.CancellationToken cancellationToken);

Parameters

function
Func<Object,TResult>

A function delegate that returns the future result to be available through the task.

state
Object

An object that contains data to be used by the function delegate.

cancellationToken
CancellationToken

The cancellation token that will be assigned to the new task.

Returns

The started task.

Exceptions

The cancellation token source that created cancellationToken has already been disposed.

The function argument is null.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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

StartNew(Func<Object,TResult>, Object, TaskCreationOptions)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object,TResult> function, object state, System.Threading.Tasks.TaskCreationOptions creationOptions);
C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object?,TResult> function, object? state, System.Threading.Tasks.TaskCreationOptions creationOptions);

Parameters

function
Func<Object,TResult>

A function delegate that returns the future result to be available through the task.

state
Object

An object that contains data to be used by the function delegate.

creationOptions
TaskCreationOptions

One of the enumeration values that controls the behavior of the created task.

Returns

The started task.

Exceptions

The function argument is null.

The creationOptions parameter specifies an invalid value.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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

StartNew(Func<TResult>, TaskCreationOptions)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function, System.Threading.Tasks.TaskCreationOptions creationOptions);

Parameters

function
Func<TResult>

A function delegate that returns the future result to be available through the task.

creationOptions
TaskCreationOptions

One of the enumeration values that controls the behavior of the created task.

Returns

The started Task<TResult>.

Exceptions

The function argument is null.

The creationOptions parameter specifies an invalid value.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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

StartNew(Func<TResult>, CancellationToken, TaskCreationOptions, TaskScheduler)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions, System.Threading.Tasks.TaskScheduler scheduler);

Parameters

function
Func<TResult>

A function delegate that returns the future result to be available through the task.

cancellationToken
CancellationToken

The cancellation token that will be assigned to the new task.

creationOptions
TaskCreationOptions

One of the enumeration values that controls the behavior of the created task.

scheduler
TaskScheduler

The task scheduler that is used to schedule the created task.

Returns

The started task.

Exceptions

The cancellation token source that created cancellationToken has already been disposed.

The function argument is null.

-or-

The scheduler argument is null.

The creationOptions parameter specifies an invalid value.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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

StartNew(Func<Object,TResult>, Object)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object,TResult> function, object state);
C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object?,TResult> function, object? state);

Parameters

function
Func<Object,TResult>

A function delegate that returns the future result to be available through the task.

state
Object

An object that contains data to be used by the function delegate.

Returns

The started task.

Exceptions

The function argument is null.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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

StartNew(Func<TResult>)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function);

Parameters

function
Func<TResult>

A function delegate that returns the future result to be available through the task.

Returns

The started task.

Exceptions

The function argument is null.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors, and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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

StartNew(Func<TResult>, CancellationToken)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function, System.Threading.CancellationToken cancellationToken);

Parameters

function
Func<TResult>

A function delegate that returns the future result to be available through the task.

cancellationToken
CancellationToken

The cancellation token that will be assigned to the new task.

Returns

The started task.

Exceptions

The cancellation token source that created cancellationToken has already been disposed.

The function argument is null.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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

StartNew(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions, TaskScheduler)

Source:
FutureFactory.cs
Source:
FutureFactory.cs
Source:
FutureFactory.cs

Creates and starts a task.

C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object,TResult> function, object state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions, System.Threading.Tasks.TaskScheduler scheduler);
C#
public System.Threading.Tasks.Task<TResult> StartNew (Func<object?,TResult> function, object? state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions, System.Threading.Tasks.TaskScheduler scheduler);

Parameters

function
Func<Object,TResult>

A function delegate that returns the future result to be available through the task.

state
Object

An object that contains data to be used by the function delegate.

cancellationToken
CancellationToken

The cancellation token that will be assigned to the new task.

creationOptions
TaskCreationOptions

One of the enumeration values that controls the behavior of the created task.

scheduler
TaskScheduler

The task scheduler that is used to schedule the created task.

Returns

The started task.

Exceptions

The cancellation token source that created cancellationToken has already been disposed.

The function argument is null.

-or-

The scheduler argument is null.

The creationOptions parameter specifies an invalid value.

Remarks

Calling StartNew is functionally equivalent to creating a task by using one of the Task<TResult> constructors and then calling the Start method to schedule it for execution.

However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

See also

Applies to

.NET 9 e outras versões
Produto Versões
.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
.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