TaskFactory<TResult>.StartNew TaskFactory<TResult>.StartNew TaskFactory<TResult>.StartNew TaskFactory<TResult>.StartNew Method

Definition

Creates and starts a task.

Overloads

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

Creates and starts a task.

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

Creates and starts a task.

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

Creates and starts a task.

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

Creates and starts a task.

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

Creates and starts a task.

StartNew(Func<TResult>) StartNew(Func<TResult>) StartNew(Func<TResult>) StartNew(Func<TResult>)

Creates and starts a task.

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

Creates and starts a task.

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

Creates and starts a task.

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

Creates and starts a task.

public:
 System::Threading::Tasks::Task<TResult> ^ StartNew(Func<System::Object ^, TResult> ^ function, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> StartNew (Func<object,TResult> function, object state, System.Threading.CancellationToken cancellationToken);
member this.StartNew : Func<obj, 'Result> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Parameters
function
Func<Object,TResult>

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

state
Object Object Object Object

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

Returns
Exceptions

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

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) StartNew(Func<Object,TResult>, Object, TaskCreationOptions) StartNew(Func<Object,TResult>, Object, TaskCreationOptions) StartNew(Func<Object,TResult>, Object, TaskCreationOptions)

Creates and starts a task.

public:
 System::Threading::Tasks::Task<TResult> ^ StartNew(Func<System::Object ^, TResult> ^ function, System::Object ^ state, System::Threading::Tasks::TaskCreationOptions creationOptions);
public System.Threading.Tasks.Task<TResult> StartNew (Func<object,TResult> function, object state, System.Threading.Tasks.TaskCreationOptions creationOptions);
member this.StartNew : Func<obj, 'Result> * obj * System.Threading.Tasks.TaskCreationOptions -> System.Threading.Tasks.Task<'Result>
Public Function StartNew (function As Func(Of Object, TResult), state As Object, creationOptions As TaskCreationOptions) As Task(Of TResult)
Parameters
function
Func<Object,TResult>

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

state
Object Object Object Object

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

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

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

Returns
Exceptions

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) StartNew(Func<TResult>, TaskCreationOptions) StartNew(Func<TResult>, TaskCreationOptions) StartNew(Func<TResult>, TaskCreationOptions)

Creates and starts a task.

public:
 System::Threading::Tasks::Task<TResult> ^ StartNew(Func<TResult> ^ function, System::Threading::Tasks::TaskCreationOptions creationOptions);
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function, System.Threading.Tasks.TaskCreationOptions creationOptions);
member this.StartNew : Func<'Result> * System.Threading.Tasks.TaskCreationOptions -> System.Threading.Tasks.Task<'Result>
Public Function StartNew (function As Func(Of TResult), creationOptions As TaskCreationOptions) As Task(Of TResult)
Parameters
function
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

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

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

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

Returns
Exceptions

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) StartNew(Func<TResult>, CancellationToken, TaskCreationOptions, TaskScheduler) 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);
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.StartNew : Func<'Result> * System.Threading.CancellationToken * System.Threading.Tasks.TaskCreationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Parameters
function
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

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

scheduler
TaskScheduler TaskScheduler TaskScheduler TaskScheduler

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

Returns
Exceptions

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

The function argument is null.

-or-

The scheduler 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) StartNew(Func<Object,TResult>, Object) StartNew(Func<Object,TResult>, Object) StartNew(Func<Object,TResult>, Object)

Creates and starts a task.

public:
 System::Threading::Tasks::Task<TResult> ^ StartNew(Func<System::Object ^, TResult> ^ function, System::Object ^ state);
public System.Threading.Tasks.Task<TResult> StartNew (Func<object,TResult> function, object state);
member this.StartNew : Func<obj, 'Result> * obj -> System.Threading.Tasks.Task<'Result>
Public Function StartNew (function As Func(Of Object, TResult), state As Object) As Task(Of TResult)
Parameters
function
Func<Object,TResult>

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

state
Object Object Object Object

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

Returns
Exceptions

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>) StartNew(Func<TResult>) StartNew(Func<TResult>) StartNew(Func<TResult>)

Creates and starts a task.

public:
 System::Threading::Tasks::Task<TResult> ^ StartNew(Func<TResult> ^ function);
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function);
member this.StartNew : Func<'Result> -> System.Threading.Tasks.Task<'Result>
Public Function StartNew (function As Func(Of TResult)) As Task(Of TResult)
Parameters
function
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

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

Returns
Exceptions

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) StartNew(Func<TResult>, CancellationToken) StartNew(Func<TResult>, CancellationToken)

Creates and starts a task.

public:
 System::Threading::Tasks::Task<TResult> ^ StartNew(Func<TResult> ^ function, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> StartNew (Func<TResult> function, System.Threading.CancellationToken cancellationToken);
member this.StartNew : Func<'Result> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Parameters
function
Func<TResult> Func<TResult> Func<TResult> Func<TResult>

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

Returns
Exceptions

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

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) StartNew(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions, TaskScheduler) StartNew(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions, TaskScheduler)

Creates and starts a task.

public:
 System::Threading::Tasks::Task<TResult> ^ StartNew(Func<System::Object ^, TResult> ^ function, System::Object ^ state, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskCreationOptions creationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
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);
member this.StartNew : Func<obj, 'Result> * obj * System.Threading.CancellationToken * System.Threading.Tasks.TaskCreationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Parameters
function
Func<Object,TResult>

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

state
Object Object Object Object

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

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

scheduler
TaskScheduler TaskScheduler TaskScheduler TaskScheduler

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

Returns
Exceptions

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

The function argument is null.

-or-

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

Applies to