TaskFactory.ContinueWhenAll 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當一組指定的工作已完成時,建立啟動的接續工作。
多載
ContinueWhenAll(Task[], Action<Task[]>)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task ^> ^> ^ continuationAction);
public System.Threading.Tasks.Task ContinueWhenAll (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task[]> continuationAction);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task[]> -> System.Threading.Tasks.Task
Public Function ContinueWhenAll (tasks As Task(), continuationAction As Action(Of Task())) As Task
參數
- tasks
- Task[]
要接續之工作的所在陣列。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
tasks
陣列為空白或包含 null 值。
範例
下列範例會啟動個別的工作,這些工作會使用正則運算式來計算一組文字檔中的字數。 方法 ContinueWhenAll 可用來啟動工作,此工作會在所有前項工作完成時顯示總字數。
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string[] filenames = { "chapter1.txt", "chapter2.txt",
"chapter3.txt", "chapter4.txt",
"chapter5.txt" };
string pattern = @"\b\w+\b";
var tasks = new List<Task>();
int totalWords = 0;
// Determine the number of words in each file.
foreach (var filename in filenames)
tasks.Add( Task.Factory.StartNew( fn => { if (! File.Exists(fn.ToString()))
throw new FileNotFoundException("{0} does not exist.", filename);
StreamReader sr = new StreamReader(fn.ToString());
String content = sr.ReadToEnd();
sr.Close();
int words = Regex.Matches(content, pattern).Count;
Interlocked.Add(ref totalWords, words);
Console.WriteLine("{0,-25} {1,6:N0} words", fn, words); },
filename));
var finalTask = Task.Factory.ContinueWhenAll(tasks.ToArray(), wordCountTasks => {
int nSuccessfulTasks = 0;
int nFailed = 0;
int nFileNotFound = 0;
foreach (var t in wordCountTasks) {
if (t.Status == TaskStatus.RanToCompletion)
nSuccessfulTasks++;
if (t.Status == TaskStatus.Faulted) {
nFailed++;
t.Exception.Handle( (e) => {
if (e is FileNotFoundException)
nFileNotFound++;
return true;
});
}
}
Console.WriteLine("\n{0,-25} {1,6} total words\n",
String.Format("{0} files", nSuccessfulTasks),
totalWords);
if (nFailed > 0) {
Console.WriteLine("{0} tasks failed for the following reasons:", nFailed);
Console.WriteLine(" File not found: {0}", nFileNotFound);
if (nFailed != nFileNotFound)
Console.WriteLine(" Other: {0}", nFailed - nFileNotFound);
}
});
finalTask.Wait();
}
}
// The example displays output like the following:
// chapter2.txt 1,585 words
// chapter1.txt 4,012 words
// chapter5.txt 4,660 words
// chapter3.txt 7,481 words
//
// 4 files 17738 total words
//
// 1 tasks failed for the following reasons:
// File not found: 1
Imports System.Collections.Generic
Imports System.IO
Imports System.Threading
Imports System.Threading.Tasks
Imports System.Text.RegularExpressions
Module Example
Dim totalWords As Integer = 0
Public Sub Main()
Dim filenames() As String = { "chapter1.txt", "chapter2.txt",
"chapter3.txt", "chapter4.txt",
"chapter5.txt" }
Dim pattern As String = "\b\w+\b"
Dim tasks As New List(Of Task)()
' Determine the number of words in each file.
For Each filename In filenames
tasks.Add(Task.Factory.StartNew( Sub(fn)
If Not File.Exists(filename)
Throw New FileNotFoundException("{0} does not exist.", filename)
End If
Dim sr As New StreamReader(fn.ToString())
Dim content As String = sr.ReadToEnd()
sr.Close()
Dim words As Integer = Regex.Matches(content, pattern).Count
Interlocked.Add(totalWords, words)
Console.WriteLine("{0,-25} {1,6:N0} words", fn, words)
End Sub, filename))
Next
Dim finalTask As Task = Task.Factory.ContinueWhenAll(tasks.ToArray(),
Sub(wordCountTasks As Task() )
Dim nSuccessfulTasks As Integer = 0
Dim nFailed As Integer = 0
Dim nFileNotFound As Integer = 0
For Each t In wordCountTasks
If t.Status = TaskStatus.RanToCompletion Then _
nSuccessfulTasks += 1
If t.Status = TaskStatus.Faulted Then
nFailed += 1
t.Exception.Handle(Function(e As Exception)
If TypeOf e Is FileNotFoundException Then
nFileNotFound += 1
End If
Return True
End Function)
End If
Next
Console.WriteLine()
Console.WriteLine("{0,-25} {1,6} total words",
String.Format("{0} files", nSuccessfulTasks),
totalWords)
If nFailed > 0 Then
Console.WriteLine()
Console.WriteLine("{0} tasks failed for the following reasons:", nFailed)
Console.WriteLine(" File not found: {0}", nFileNotFound)
If nFailed <> nFileNotFound Then
Console.WriteLine(" Other: {0}", nFailed - nFileNotFound)
End If
End If
End Sub)
finalTask.Wait()
End Sub
Private Sub DisplayResult(wordCountTasks As Task())
End Sub
End Module
' The example displays output like the following:
' chapter2.txt 1,585 words
' chapter1.txt 4,012 words
' chapter5.txt 4,660 words
' chapter3.txt 7,481 words
'
' 4 files 17738 total words
'
' 1 tasks failed for the following reasons:
' File not found: 1
呼叫接續工作的 Task.Wait 方法不允許它處理前項工作擲回的例外狀況,因此此範例會 Task.Status 檢查每個前項工作的 屬性,以判斷工作是否成功。
備註
ContinueWhenAll方法會在 continuationAction
陣列中的所有工作 tasks
都完成時執行委派,而不論其完成狀態為何。
陣列中工作擲回的 tasks
例外狀況無法透過結構化例外狀況處理,供接續工作使用。 您可以檢查 Task.Exception 陣列中 tasks
每個工作的 屬性,以判斷擲回的例外狀況。 若要使用結構化例外狀況處理來處理陣列中工作擲回的 tasks
例外狀況,請呼叫 Task.WaitAll(Task[]) 方法。
另請參閱
適用於
ContinueWhenAll(Task[], Action<Task[]>, CancellationToken)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task ^> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWhenAll (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task[]> continuationAction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task[]> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWhenAll (tasks As Task(), continuationAction As Action(Of Task()), cancellationToken As CancellationToken) As Task
參數
- tasks
- Task[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
範例
下列範例會建立解除標記,它會傳遞至使用正則運算式來計算一組文字檔中單字數目的個別工作。 如果找不到檔案,則會設定解除標記。 方法 ContinueWhenAll(Task[], Action{Task[]}, CancellationToken)
可用來啟動工作,此工作會在所有前項工作完成時顯示總字數。 如果已設定解除標記,表示已取消一或多個工作,它會處理 AggregateException 例外狀況並顯示錯誤訊息。
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string[] filenames = { "chapter1.txt", "chapter2.txt",
"chapter3.txt", "chapter4.txt",
"chapter5.txt" };
string pattern = @"\b\w+\b";
var tasks = new List<Task>();
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
int totalWords = 0;
// Determine the number of words in each file.
foreach (var filename in filenames)
tasks.Add( Task.Factory.StartNew( fn => { token.ThrowIfCancellationRequested();
if (! File.Exists(fn.ToString())) {
source.Cancel();
token.ThrowIfCancellationRequested();
}
StreamReader sr = new StreamReader(fn.ToString());
String content = sr.ReadToEnd();
sr.Close();
int words = Regex.Matches(content, pattern).Count;
Interlocked.Add(ref totalWords, words);
Console.WriteLine("{0,-25} {1,6:N0} words", fn, words); },
filename, token));
var finalTask = Task.Factory.ContinueWhenAll(tasks.ToArray(), wordCountTasks => {
if (! token.IsCancellationRequested)
Console.WriteLine("\n{0,-25} {1,6} total words\n",
String.Format("{0} files", wordCountTasks.Length),
totalWords);
}, token);
try {
finalTask.Wait();
}
catch (AggregateException ae) {
foreach (Exception inner in ae.InnerExceptions)
if (inner is TaskCanceledException)
Console.WriteLine("\nFailure to determine total word count: a task was cancelled.");
else
Console.WriteLine("\nFailure caused by {0}", inner.GetType().Name);
}
finally {
source.Dispose();
}
}
}
// The example displays output like the following:
// chapter2.txt 1,585 words
// chapter1.txt 4,012 words
//
// Failure to determine total word count: a task was cancelled.
Imports System.Collections.Generic
Imports System.IO
Imports System.Threading
Imports System.Threading.Tasks
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim filenames() As String= { "chapter1.txt", "chapter2.txt",
"chapter3.txt", "chapter4.txt",
"chapter5.txt" }
Dim pattern As String = "\b\w+\b"
Dim tasks As New List(Of Task)()
Dim source As New CancellationTokenSource()
Dim token As CancellationToken = source.Token
Dim totalWords As Integer = 0
' Determine the number of words in each file.
For Each filename In filenames
tasks.Add( Task.Factory.StartNew( Sub(obj As Object)
Dim fn As String = CStr(obj)
token.ThrowIfCancellationRequested()
If Not File.Exists(fn) Then
source.Cancel()
token.ThrowIfCancellationRequested()
End If
Dim sr As New StreamReader(fn.ToString())
Dim content As String = sr.ReadToEnd()
sr.Close()
Dim words As Integer = Regex.Matches(content, pattern).Count
Interlocked.Add(totalWords, words)
Console.WriteLine("{0,-25} {1,6:N0} words", fn, words)
End Sub, filename, token))
Next
Dim finalTask As Task = Task.Factory.ContinueWhenAll(tasks.ToArray(),
Sub(wordCountTasks As Task())
If Not token.IsCancellationRequested Then
Console.WriteLine("\n{0,-25} {1,6} total words\n",
String.Format("{0} files", wordCountTasks.Length),
totalWords)
End If
End Sub, token)
Try
finalTask.Wait()
Catch ae As AggregateException
For Each inner In ae.InnerExceptions
Console.WriteLine()
If TypeOf inner Is TaskCanceledException
Console.WriteLine("Failure to determine total word count: a task was cancelled.")
Else
Console.WriteLine("Failure caused by {0}", inner.GetType().Name)
End If
Next
Finally
source.Dispose()
End Try
End Sub
End Module
' The example displays output like the following:
' chapter2.txt 1,585 words
' chapter1.txt 4,012 words
'
' Failure to determine total word count: a task was cancelled.
備註
這個方法會在 continuationAction
陣列中的所有 tasks
工作都完成時執行委派,而不論其完成狀態為何。
另請參閱
適用於
ContinueWhenAll(Task[], Action<Task[]>, TaskContinuationOptions)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task ^> ^> ^ continuationAction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWhenAll (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task[]> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task[]> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWhenAll (tasks As Task(), continuationAction As Action(Of Task()), continuationOptions As TaskContinuationOptions) As Task
參數
- tasks
- Task[]
要接續之工作的所在陣列。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。 不支援 NotOn* 和 OnlyOn* 成員。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
continuationOptions
引數指定了無效的值。
tasks
陣列為空白或包含 null 值。
備註
NotOn 和 OnlyOn * * TaskContinuationOptions ,其限制 TaskStatus 會執行接續的狀態,使用 ContinueWhenAll
不合法。
另請參閱
適用於
ContinueWhenAll(Task[], Action<Task[]>, CancellationToken, TaskContinuationOptions, TaskScheduler)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task ^> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWhenAll (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task[]> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task[]> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWhenAll (tasks As Task(), continuationAction As Action(Of Task()), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task
參數
- tasks
- Task[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。
- scheduler
- TaskScheduler
用來排定新接續工作的物件。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
continuationOptions
指定無效的 TaskContinuationOptions 值。
提供的 CancellationToken 已經過處置。
備註
NotOn 和 OnlyOn * * TaskContinuationOptions ,其限制 TaskStatus 會執行接續的狀態,使用 ContinueWhenAll
不合法。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[],TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>[],TResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>[], 'Result> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult)(), TResult), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TResult)
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。 不支援 NotOn* 和 OnlyOn* 成員。
- scheduler
- TaskScheduler
用來排定新接續工作的物件。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
continuationOptions
引數指定了無效的值。
備註
NotOn * 和 OnlyOn * TaskContinuationOptions ,其限制 TaskStatus 將執行接續的狀態,與 ContinueWhenAll
不合法。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[],TResult>, TaskContinuationOptions)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^, TResult> ^ continuationFunction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>[],TResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>[], 'Result> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult)(), TResult), continuationOptions As TaskContinuationOptions) As Task(Of TResult)
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。 不支援 NotOn* 和 OnlyOn* 成員。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
continuationOptions
引數指定了無效的值。
tasks
陣列為空白或包含 null 值。
備註
NotOn * 和 OnlyOn * TaskContinuationOptions ,其限制 TaskStatus 將執行接續的狀態,與 ContinueWhenAll
不合法。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[],TResult>, CancellationToken)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>[],TResult> continuationFunction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>[], 'Result> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult)(), TResult), cancellationToken As CancellationToken) As Task(Of TResult)
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>[],TResult>)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^, TResult> ^ continuationFunction);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>[],TResult> continuationFunction);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>[], 'Result> -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult)(), TResult)) As Task(Of TResult)
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
tasks
陣列為空白或包含 null 值。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>, CancellationToken, TaskContinuationOptions, TaskScheduler)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWhenAll<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>[]> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>[]> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWhenAll(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult)()), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。 不支援 NotOn* 和 OnlyOn* 成員。
- scheduler
- TaskScheduler
用來排定新接續工作的物件。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
continuationOptions
指定無效的 TaskContinuationOptions 值。
提供的 CancellationToken 已經過處置。
備註
NotOn 和 OnlyOn * * TaskContinuationOptions ,其限制 TaskStatus 會執行接續的狀態,使用 ContinueWhenAll
不合法。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>, TaskContinuationOptions)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^> ^ continuationAction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWhenAll<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>[]> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>[]> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWhenAll(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult)()), continuationOptions As TaskContinuationOptions) As Task
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。 不支援 NotOn* 和 OnlyOn* 成員。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
continuationOptions
引數指定了無效的值。
tasks
陣列為空白或包含 null 值。
備註
NotOn 和 OnlyOn * * TaskContinuationOptions ,其限制 TaskStatus 會執行接續的狀態,使用 ContinueWhenAll
不合法。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>, CancellationToken)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWhenAll<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>[]> continuationAction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>[]> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWhenAll(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult)()), cancellationToken As CancellationToken) As Task
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
另請參閱
適用於
ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>[]>)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^> ^ continuationAction);
public System.Threading.Tasks.Task ContinueWhenAll<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>[]> continuationAction);
member this.ContinueWhenAll : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>[]> -> System.Threading.Tasks.Task
Public Function ContinueWhenAll(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult)())) As Task
類型參數
- TAntecedentResult
前項 tasks
的結果類型。
參數
- tasks
- Task<TAntecedentResult>[]
要接續之工作的所在陣列。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
tasks
陣列為空白或包含 null 值。
另請參閱
適用於
ContinueWhenAll<TResult>(Task[], Func<Task[],TResult>)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task ^> ^, TResult> ^ continuationFunction);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task[],TResult> continuationFunction);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task[], 'Result> -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task(), TResult)) As Task(Of TResult)
類型參數
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task[]
要接續之工作的所在陣列。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
tasks
陣列為空白或包含 null 值。
另請參閱
適用於
ContinueWhenAll<TResult>(Task[], Func<Task[],TResult>, CancellationToken)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task ^> ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task[],TResult> continuationFunction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task[], 'Result> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task(), TResult), cancellationToken As CancellationToken) As Task(Of TResult)
類型參數
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
另請參閱
適用於
ContinueWhenAll<TResult>(Task[], Func<Task[],TResult>, TaskContinuationOptions)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task ^> ^, TResult> ^ continuationFunction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task[],TResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task[], 'Result> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task(), TResult), continuationOptions As TaskContinuationOptions) As Task(Of TResult)
類型參數
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task[]
要接續之工作的所在陣列。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。 不支援 NotOn* 和 OnlyOn* 成員。
傳回
新的接續工作。
例外狀況
已處置之 tasks
陣列中的項目。
continuationOptions
引數指定了無效的值。
tasks
陣列為空白或包含 null 值。
備註
NotOn 和 OnlyOn * * TaskContinuationOptions ,其限制 TaskStatus 會執行接續的狀態,使用 ContinueWhenAll
不合法。
另請參閱
適用於
ContinueWhenAll<TResult>(Task[], Func<Task[],TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)
當一組指定的工作已完成時,建立啟動的接續工作。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAll(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<cli::array <System::Threading::Tasks::Task ^> ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWhenAll<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task[],TResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAll : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task[], 'Result> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAll(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task(), TResult), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TResult)
類型參數
- TResult
由 continuationFunction
委派傳回,且與建立之工作相關聯的結果的類型。
參數
- tasks
- Task[]
要接續之工作的所在陣列。
- cancellationToken
- CancellationToken
要指派給新接續工作的取消語彙基元。
- continuationOptions
- TaskContinuationOptions
列舉值的位元組合,這些值會控制新接續工作的行為。 不支援 NotOn* 和 OnlyOn* 成員。
- scheduler
- TaskScheduler
用來排定新接續工作的物件。
傳回
新的接續工作。
例外狀況
tasks
陣列為空白或包含 null 值。
continuationOptions
指定無效的 TaskContinuationOptions 值。
提供的 CancellationToken 已經過處置。
備註
NotOn 和 OnlyOn * * TaskContinuationOptions ,其限制 TaskStatus 會執行接續的狀態,使用 ContinueWhenAll
不合法。