TaskFactory<TResult>.StartNew 方法

定義

建立並啟動工作。Creates and starts a task.

多載

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

參數

function
Func<Object,TResult>

函式委派,會傳回將可透過工作使用的未來結果。A function delegate that returns the future result to be available through the task.

state
Object

物件,包含 function 委派所要使用的資料。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.

傳回

已開始的工作。The started task.

例外狀況

已處置建立 cancellationToken 的取消語彙基元來源。The cancellation token source that created cancellationToken has already been disposed.

function 引數為 nullThe function argument is null.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。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<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)

參數

function
Func<Object,TResult>

函式委派,會傳回將可透過工作使用的未來結果。A function delegate that returns the future result to be available through the task.

state
Object

物件,包含 function 委派所要使用的資料。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.

傳回

已開始的工作。The started task.

例外狀況

function 引數為 nullThe function argument is null.

creationOptions 參數指定了無效的值。The creationOptions parameter specifies an invalid value.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。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);
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)

參數

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.

傳回

啟動的 Task<TResult>The started Task<TResult>.

例外狀況

function 引數為 nullThe function argument is null.

creationOptions 參數指定了無效的值。The creationOptions parameter specifies an invalid value.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。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);
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>

參數

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.

傳回

已開始的工作。The started task.

例外狀況

已處置建立 cancellationToken 的取消語彙基元來源。The cancellation token source that created cancellationToken has already been disposed.

function 引數為 nullThe function argument is null.

-或--or- scheduler 引數為 nullThe scheduler argument is null.

creationOptions 參數指定了無效的值。The creationOptions parameter specifies an invalid value.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。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<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)

參數

function
Func<Object,TResult>

函式委派,會傳回將可透過工作使用的未來結果。A function delegate that returns the future result to be available through the task.

state
Object

物件,包含 function 委派所要使用的資料。An object that contains data to be used by the function delegate.

傳回

已開始的工作。The started task.

例外狀況

function 引數為 nullThe function argument is null.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。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);
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)

參數

function
Func<TResult>

函式委派,會傳回將可透過工作使用的未來結果。A function delegate that returns the future result to be available through the task.

傳回

已開始的工作。The started task.

例外狀況

function 引數為 nullThe function argument is null.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。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);
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>

參數

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.

傳回

已開始的工作。The started task.

例外狀況

已處置建立 cancellationToken 的取消語彙基元來源。The cancellation token source that created cancellationToken has already been disposed.

function 引數為 nullThe function argument is null.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。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<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>

參數

function
Func<Object,TResult>

函式委派,會傳回將可透過工作使用的未來結果。A function delegate that returns the future result to be available through the task.

state
Object

物件,包含 function 委派所要使用的資料。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.

傳回

已開始的工作。The started task.

例外狀況

已處置建立 cancellationToken 的取消語彙基元來源。The cancellation token source that created cancellationToken has already been disposed.

function 引數為 nullThe function argument is null.

-或--or- scheduler 引數為 nullThe scheduler argument is null.

creationOptions 參數指定了無效的值。The creationOptions parameter specifies an invalid value.

備註

呼叫StartNew相當於使用其中一種建立工作Task<TResult>建構函式,然後呼叫Start排程執行的方法。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.

不過,除非您建立和排程必須分隔,StartNew是為了簡化和效能的建議的方法。However, unless creation and scheduling must be separated, StartNew is the recommended approach for both simplicity and performance.

另請參閱

適用於