Uređivanje

Dijeli putem


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)

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

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);
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>
Public Function StartNew (function As Func(Of Object, TResult), state As Object, cancellationToken As CancellationToken) 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

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

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

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

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);
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

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

StartNew(Func<TResult>, TaskCreationOptions)

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

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>

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

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

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

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>
Public Function StartNew (function As Func(Of TResult), cancellationToken As CancellationToken, creationOptions As TaskCreationOptions, scheduler As TaskScheduler) As Task(Of TResult)

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

StartNew(Func<Object,TResult>, Object)

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

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);
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

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

StartNew(Func<TResult>)

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

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>

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

StartNew(Func<TResult>, CancellationToken)

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

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>
Public Function StartNew (function As Func(Of TResult), cancellationToken As CancellationToken) As Task(Of TResult)

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

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

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

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);
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>
Public Function StartNew (function As Func(Of Object, TResult), state As Object, cancellationToken As CancellationToken, creationOptions As TaskCreationOptions, scheduler As TaskScheduler) 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

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