TaskFactory<TResult>.StartNew Method

Definition

Creates and starts a task.

Overloads

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

Creates and starts a task.

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

Creates and starts a task.

StartNew(Func<TResult>, TaskCreationOptions)

Creates and starts a task.

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

Creates and starts a task.

StartNew(Func<Object,TResult>, Object)

Creates and starts a task.

StartNew(Func<TResult>)

Creates and starts a task.

StartNew(Func<TResult>, CancellationToken)

Creates and starts a task.

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

Creates and starts a task.

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

Creates and starts a task.

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.

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

Creates and starts a task.

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.

StartNew(Func<TResult>, TaskCreationOptions)

Creates and starts a task.

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
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.

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

Creates and starts a task.

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.

StartNew(Func<Object,TResult>, Object)

Creates and starts a task.

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.

StartNew(Func<TResult>)

Creates and starts a task.

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.

StartNew(Func<TResult>, CancellationToken)

Creates and starts a task.

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.

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

Creates and starts a task.

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.

Applies to