Task<TResult>.ContinueWith Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee maakt u een vervolgtaak die wordt uitgevoerd wanneer een andere taak is voltooid.
Overloads
| Name | Description |
|---|---|
| ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler) |
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in |
| ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) |
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in |
| ContinueWith(Action<Task<TResult>>, CancellationToken) |
Hiermee maakt u een geannuleerde vervolg die asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith(Action<Task<TResult>,Object>, Object) |
Hiermee maakt u een vervolg dat statusinformatie doorgeeft en die wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith(Action<Task<TResult>>) |
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer de doeltaak is voltooid. |
| ContinueWith(Action<Task<TResult>>, TaskScheduler) |
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) |
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in |
| ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions) |
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in |
| ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken) |
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object) |
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>) |
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
| ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler) |
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid. |
ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>,object> continuationAction, object state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>, obj> * obj * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult), Object), state As Object, cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de bewerking Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgactie.
- cancellationToken
- CancellationToken
De CancellationToken taak die wordt toegewezen aan de nieuwe vervolgtaak.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
Het scheduler argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
De opgegeven CancellationToken is al verwijderd.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid. Als niet wordt voldaan aan de criteria die via de continuationOptions parameter zijn opgegeven, wordt de vervolgtaak geannuleerd in plaats van gepland.
Zie ook
Van toepassing op
ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler)
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in continuationOptions.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult)), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task
Parameters
Een actie die moet worden uitgevoerd volgens de voorwaarde die is opgegeven in continuationOptions. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
- cancellationToken
- CancellationToken
De CancellationToken taak die wordt toegewezen aan de nieuwe vervolgtaak.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
De Task<TResult> is verwijderd.
– of –
De CancellationTokenSource gemaakte cancellationToken is al verwijderd.
Het continuationAction argument is null.
– of –
Het scheduler argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid. Als niet wordt voldaan aan de criteria die via de continuationOptions parameter zijn opgegeven, wordt de vervolgtaak geannuleerd in plaats van gepland. Zie Taken koppelen door vervolgtaken te gebruikenvoor meer informatie.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>,object> continuationAction, object state, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>, obj> * obj * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult), Object), state As Object, scheduler As TaskScheduler) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de bewerking Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgactie.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
Het scheduler argument is null.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
Van toepassing op
ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>,object> continuationAction, object state, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>, obj> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult), Object), state As Object, cancellationToken As CancellationToken) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de bewerking Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgactie.
- cancellationToken
- CancellationToken
De CancellationToken taak die wordt toegewezen aan de nieuwe vervolgtaak.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
Het continuationAction argument is null.
De opgegeven CancellationToken is al verwijderd.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
Van toepassing op
ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>,object> continuationAction, object state, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>, obj> * obj * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult), Object), state As Object, continuationOptions As TaskContinuationOptions) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de bewerking Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgactie.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
Het continuationAction argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid. Als niet wordt voldaan aan de vervolgcriteria die via de continuationOptions parameter zijn opgegeven, wordt de vervolgtaak geannuleerd in plaats van gepland.
Zie ook
Van toepassing op
ContinueWith(Action<Task<TResult>>, TaskContinuationOptions)
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in continuationOptions.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^> ^ continuationAction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult)), continuationOptions As TaskContinuationOptions) As Task
Parameters
Een actie op basis van de voorwaarde die is opgegeven in continuationOptions. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
De Task<TResult> is verwijderd.
Het continuationAction argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid. Als niet wordt voldaan aan de vervolgcriteria die via de continuationOptions parameter zijn opgegeven, wordt de vervolgtaak geannuleerd in plaats van gepland.
Zie Taken koppelen door vervolgtaken te gebruikenvoor meer informatie.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith(Action<Task<TResult>>, CancellationToken)
Hiermee maakt u een geannuleerde vervolg die asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>> continuationAction, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult)), cancellationToken As CancellationToken) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de bewerking Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
- cancellationToken
- CancellationToken
Het annuleringstoken dat wordt doorgegeven aan de nieuwe vervolgtaak.
Retouren
Een nieuwe vervolgtaak.
Uitzonderingen
De Task<TResult> is verwijderd.
– of –
De CancellationTokenSource gemaakte cancellationToken is verwijderd.
Het continuationAction argument is null.
Voorbeelden
In het volgende voorbeeld wordt een antecedenttaak gemaakt die gebruikmaakt van de zeef van Eratosthenes om de priemgetallen tussen 1 en een waarde te berekenen die door de gebruiker is ingevoerd. Een matrix wordt gebruikt om informatie over de priemgetallen te bewaren. De matrixindex vertegenwoordigt het getal en de waarde van het element geeft aan of dat getal samengesteld is (de waarde is true) of priem (de waarde is false). Deze taak wordt vervolgens doorgegeven aan een vervolgtaak, die verantwoordelijk is voor het extraheren van de priemgetallen uit de matrix met gehele getallen en het weergeven ervan.
Er wordt een annuleringstoken doorgegeven aan zowel de antecedent als de vervolgtaak. Een System.Timers.Timer object wordt gebruikt om een time-outwaarde van 100 milliseconden te definiëren. Als de gebeurtenis wordt geactiveerd, wordt de CancellationTokenSource.Cancel methode aangeroepen en wordt het annuleringstoken gebruikt om annulering van de taken aan te vragen.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Timers = System.Timers;
public class Example
{
static CancellationTokenSource ts;
public static void Main(string[] args)
{
int upperBound = args.Length >= 1 ? Int32.Parse(args[0]) : 200;
ts = new CancellationTokenSource();
CancellationToken token = ts.Token;
Timers.Timer timer = new Timers.Timer(3000);
timer.Elapsed += TimedOutEvent;
timer.AutoReset = false;
timer.Enabled = true;
var t1 = Task.Run(() => { // True = composite.
// False = prime.
bool[] values = new bool[upperBound + 1];
for (int ctr = 2; ctr <= (int) Math.Sqrt(upperBound); ctr++) {
if (!values[ctr] ) {
for (int product = ctr * ctr; product <= upperBound;
product = product + ctr)
values[product] = true;
}
token.ThrowIfCancellationRequested();
}
return values; }, token);
var t2 = t1.ContinueWith( (antecedent) => { // Create a list of prime numbers.
var primes = new List<int>();
token.ThrowIfCancellationRequested();
bool[] numbers = antecedent.Result;
string output = String.Empty;
for (int ctr = 1; ctr <= numbers.GetUpperBound(0); ctr++)
if (!numbers[ctr] )
primes.Add(ctr);
// Create the output string.
for (int ctr = 0; ctr < primes.Count; ctr++) {
token.ThrowIfCancellationRequested();
output += primes[ctr].ToString("N0");
if (ctr < primes.Count - 1)
output += ", ";
if ((ctr + 1) % 8 == 0)
output += Environment.NewLine;
}
//Display the result.
Console.WriteLine("Prime numbers from 1 to {0}:\n",
upperBound);
Console.WriteLine(output);
}, token);
try {
t2.Wait();
}
catch (AggregateException ae) {
foreach (var e in ae.InnerExceptions) {
if (e.GetType() == typeof(TaskCanceledException))
Console.WriteLine("The operation was cancelled.");
else
Console.WriteLine("ELSE: {0}: {1}", e.GetType().Name, e.Message);
}
}
finally {
ts.Dispose();
}
}
private static void TimedOutEvent(Object source, Timers.ElapsedEventArgs e)
{
ts.Cancel();
}
}
// If cancellation is not requested, the example displays output like the following:
// Prime numbers from 1 to 400:
//
// 1, 2, 3, 5, 7, 11, 13, 17,
// 19, 23, 29, 31, 37, 41, 43, 47,
// 53, 59, 61, 67, 71, 73, 79, 83,
// 89, 97, 101, 103, 107, 109, 113, 127,
// 131, 137, 139, 149, 151, 157, 163, 167,
// 173, 179, 181, 191, 193, 197, 199, 211,
// 223, 227, 229, 233, 239, 241, 251, 257,
// 263, 269, 271, 277, 281, 283, 293, 307,
// 311, 313, 317, 331, 337, 347, 349, 353,
// 359, 367, 373, 379, 383, 389, 397, 401
// If cancellation is requested, the example displays output like the following:
// The operation was cancelled.
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks
Imports Timers = System.Timers
Module Example
Dim ts As CancellationTokenSource
Public Sub Main(args() As String)
Dim upperBound As Integer = If(args.Length >= 1, CInt(args(0)), 200)
ts = New CancellationTokenSource()
Dim token As CancellationToken = ts.Token
Dim timer As New Timers.Timer(100)
AddHandler timer.Elapsed, AddressOf TimedOutEvent
timer.AutoReset = False
timer.Enabled = True
Dim t1 = Task.Run(Function()
' True = composite.
' False = prime.
Dim values(upperBound) As Boolean
For ctr = 2 To CInt(Math.Sqrt(upperBound))
If values(ctr) = False Then
For product = ctr * ctr To upperBound Step ctr
values(product) = True
Next
End If
token.ThrowIfCancellationRequested()
Next
Return values
End Function, token)
Dim t2 = t1.ContinueWith(Sub(antecedent)
' Create a list of prime numbers.
Dim primes As New List(Of Integer)()
token.ThrowIfCancellationRequested()
Dim numbers As Boolean() = antecedent.Result
Dim output As String = String.Empty
For ctr As Integer = 1 To numbers.GetUpperBound(0)
If numbers(ctr) = False Then primes.Add(ctr)
Next
' Create the output string.
For ctr As Integer = 0 To primes.Count - 1
token.ThrowIfCancellationRequested()
output += primes(ctr).ToString("N0")
If ctr < primes.Count - 1 Then output += ", "
If (ctr + 1) Mod 8 = 0 Then output += vbCrLf
Next
'Display the result.
Console.WriteLine("Prime numbers from 1 to {0}:{1}",
upperBound, vbCrLf)
Console.WriteLine(output)
End Sub, token)
Try
t2.Wait()
Catch ae As AggregateException
For Each e In ae.InnerExceptions
If e.GetType Is GetType(TaskCanceledException) Then
Console.WriteLine("The operation was cancelled.")
Else
Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message)
End If
Next
Finally
ts.Dispose()
End Try
End Sub
Private Sub TimedOutEvent(source As Object, e As Timers.ElapsedEventArgs)
ts.Cancel()
End Sub
End Module
' If cancellation is not requested, the example displays output like the following:
' Prime numbers from 1 to 400:
'
' 1, 2, 3, 5, 7, 11, 13, 17,
' 19, 23, 29, 31, 37, 41, 43, 47,
' 53, 59, 61, 67, 71, 73, 79, 83,
' 89, 97, 101, 103, 107, 109, 113, 127,
' 131, 137, 139, 149, 151, 157, 163, 167,
' 173, 179, 181, 191, 193, 197, 199, 211,
' 223, 227, 229, 233, 239, 241, 251, 257,
' 263, 269, 271, 277, 281, 283, 293, 307,
' 311, 313, 317, 331, 337, 347, 349, 353,
' 359, 367, 373, 379, 383, 389, 397, 401
' If cancellation is requested, the example displays output like the following:
' The operation was cancelled.
Normaal gesproken zorgt het opgeven van een waarde van ongeveer 100.000 ervoor dat het time-outinterval verloopt en de Timer.Elapsed gebeurtenis wordt geactiveerd en dat de annuleringsaanvraag wordt ingesteld.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith(Action<Task<TResult>,Object>, Object)
Hiermee maakt u een vervolg dat statusinformatie doorgeeft en die wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^, System::Object ^> ^ continuationAction, System::Object ^ state);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>,object> continuationAction, object state);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>, obj> * obj -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult), Object), state As Object) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de bewerking Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak doorgegeven en wordt het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgactie.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
Het continuationAction argument is null.
Voorbeelden
In het volgende voorbeeld wordt een taak gemaakt die een geheel getal tussen 2 en 20 doorgeeft en een matrix retourneert die de eerste tien exponenten (van n1 tot n10) van dat getal bevat. Een vervolgtaak is vervolgens verantwoordelijk voor het weergeven van de exponenten. Het wordt zowel de antecedent als het oorspronkelijke getal doorgegeven waarvan de exponent de antecedent genereert.
using System;
using System.Threading;
using System.Threading.Tasks;
public class Example
{
public static void Main()
{
var cts = new CancellationTokenSource();
var token = cts.Token;
// Get an integer to generate a list of its exponents.
var rnd = new Random();
var number = rnd.Next(2, 21);
var t = Task.Factory.StartNew( (value) => { int n = (int) value;
long[] values = new long[10];
for (int ctr = 1; ctr <= 10; ctr++)
values[ctr - 1] = (long) Math.Pow(n, ctr);
return values;
}, number);
var continuation = t.ContinueWith( (antecedent, value) => { Console.WriteLine("Exponents of {0}:", value);
for (int ctr = 0; ctr <= 9; ctr++)
Console.WriteLine(" {0} {1} {2} = {3:N0}",
value, "\u02C6", ctr + 1,
antecedent.Result[ctr]);
Console.WriteLine();
}, number);
continuation.Wait();
cts.Dispose();
}
}
// The example displays output like the following:
// Exponents of 2:
// 2 ^ 1 = 2
// 2 ^ 2 = 4
// 2 ^ 3 = 8
// 2 ^ 4 = 16
// 2 ^ 5 = 32
// 2 ^ 6 = 64
// 2 ^ 7 = 128
// 2 ^ 8 = 256
// 2 ^ 9 = 512
// 2 ^ 10 = 1,024
Imports System.Threading
Imports System.Threading.Tasks
Module Example
Public Sub Main()
Dim cts As New CancellationTokenSource()
Dim token As CancellationToken = cts.Token
' Get an integer to generate a list of its exponents.
Dim rnd As New Random()
Dim number As Integer = rnd.Next(2, 21)
Dim t = Task.Factory.StartNew( Function(value)
Dim n As Integer = CInt(value)
Dim values(9) As Long
For ctr As Integer = 1 To 10
values(ctr - 1) = CLng(Math.Pow(n, ctr))
Next
return values
End Function, number)
Dim continuation = t.ContinueWith( Sub(antecedent, value)
Console.WriteLine("Exponents of {0}:", value)
For ctr As Integer = 0 To 9
Console.WriteLine(" {0} {1} {2} = {3:N0}",
value, ChrW(&h02C6), ctr + 1,
antecedent.Result(ctr))
Next
Console.WriteLine()
End Sub, number)
continuation.Wait()
cts.Dispose()
End Sub
End Module
' The example displays output like the following:
' Exponents of 2:
' 2 ^ 1 = 2
' 2 ^ 2 = 4
' 2 ^ 3 = 8
' 2 ^ 4 = 16
' 2 ^ 5 = 32
' 2 ^ 6 = 64
' 2 ^ 7 = 128
' 2 ^ 8 = 256
' 2 ^ 9 = 512
' 2 ^ 10 = 1,024
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
Van toepassing op
ContinueWith(Action<Task<TResult>>)
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer de doeltaak is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^> ^ continuationAction);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>> continuationAction);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>> -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult))) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de antecedent Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
Retouren
Een nieuwe vervolgtaak.
Uitzonderingen
De Task<TResult> is verwijderd.
Het continuationAction argument is null.
Voorbeelden
In het volgende voorbeeld wordt een antecedenttaak gemaakt die gebruikmaakt van de zeef van Eratosthenes om de priemgetallen tussen 1 en een waarde te berekenen die door de gebruiker is ingevoerd. Een matrix wordt gebruikt om informatie over de priemgetallen te bewaren. De matrixindex vertegenwoordigt het getal en de waarde van het element geeft aan of dat getal samengesteld is (de waarde is true) of priem (de waarde is false). Deze taak wordt vervolgens doorgegeven aan een vervolgtaak, die verantwoordelijk is voor het extraheren van de priemgetallen uit de matrix met gehele getallen en het weergeven ervan.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
public class Example
{
public static void Main(string[] args)
{
int upperBound = args.Length >= 1 ? Int32.Parse(args[0]) : 200;
var t1 = Task.Run(() => { // True = composite.
// False = prime.
bool[] values = new bool[upperBound + 1];
for (int ctr = 2; ctr <= (int) Math.Sqrt(upperBound); ctr++) {
if (!values[ctr]) {
for (int product = ctr * ctr; product <= upperBound;
product = product + ctr)
values[product] = true;
}
}
return values; });
var t2 = t1.ContinueWith( (antecedent) => { // Create a list of prime numbers.
var primes = new List<int>();
bool[] numbers = antecedent.Result;
string output = String.Empty;
for (int ctr = 1; ctr <= numbers.GetUpperBound(0); ctr++)
if (!numbers[ctr])
primes.Add(ctr);
// Create the output string.
for (int ctr = 0; ctr < primes.Count; ctr++) {
output += primes[ctr].ToString("N0");
if (ctr < primes.Count - 1)
output += ", ";
if ((ctr + 1) % 8 == 0)
output += Environment.NewLine;
}
//Display the result.
Console.WriteLine("Prime numbers from 1 to {0}:\n",
upperBound);
Console.WriteLine(output);
});
try {
t2.Wait();
}
catch (AggregateException ae) {
foreach (var e in ae.InnerExceptions)
Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
}
}
}
// The example displays output like the following:
// Prime numbers from 1 to 400:
//
// 1, 2, 3, 5, 7, 11, 13, 17,
// 19, 23, 29, 31, 37, 41, 43, 47,
// 53, 59, 61, 67, 71, 73, 79, 83,
// 89, 97, 101, 103, 107, 109, 113, 127,
// 131, 137, 139, 149, 151, 157, 163, 167,
// 173, 179, 181, 191, 193, 197, 199, 211,
// 223, 227, 229, 233, 239, 241, 251, 257,
// 263, 269, 271, 277, 281, 283, 293, 307,
// 311, 313, 317, 331, 337, 347, 349, 353,
// 359, 367, 373, 379, 383, 389, 397, 401
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks
Module Example
Public Sub Main(args() As String)
Dim upperBound As Integer = If(args.Length >= 1, CInt(args(0)), 200)
Dim t1 = Task.Run(Function()
' True = composite.
' False = prime.
Dim values(upperBound) As Boolean
For ctr = 2 To CInt(Math.Sqrt(upperBound))
If values(ctr) = False Then
For product = ctr * ctr To upperBound Step ctr
values(product) = True
Next
End If
Next
Return values
End Function)
Dim t2 = t1.ContinueWith(Sub(antecedent)
' Create a list of prime numbers.
Dim primes As New List(Of Integer)()
Dim numbers As Boolean() = antecedent.Result
Dim output As String = String.Empty
For ctr As Integer = 1 To numbers.GetUpperBound(0)
If numbers(ctr) = False Then primes.Add(ctr)
Next
' Create the output string.
For ctr As Integer = 0 To primes.Count - 1
output += primes(ctr).ToString("N0")
If ctr < primes.Count - 1 Then output += ", "
If (ctr + 1) Mod 8 = 0 Then output += vbCrLf
Next
'Display the result.
Console.WriteLine("Prime numbers from 1 to {0}:{1}",
upperBound, vbCrLf)
Console.WriteLine(output)
End Sub)
Try
t2.Wait()
Catch ae As AggregateException
For Each e In ae.InnerExceptions
Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message)
Next
End Try
End Sub
End Module
' The example displays output like the following:
' Prime numbers from 1 to 400:
'
' 1, 2, 3, 5, 7, 11, 13, 17,
' 19, 23, 29, 31, 37, 41, 43, 47,
' 53, 59, 61, 67, 71, 73, 79, 83,
' 89, 97, 101, 103, 107, 109, 113, 127,
' 131, 137, 139, 149, 151, 157, 163, 167,
' 173, 179, 181, 191, 193, 197, 199, 211,
' 223, 227, 229, 233, 239, 241, 251, 257,
' 263, 269, 271, 277, 281, 283, 293, 307,
' 311, 313, 317, 331, 337, 347, 349, 353,
' 359, 367, 373, 379, 383, 389, 397, 401
' If cancellation is requested, the example displays output like the following:
' The operation was cancelled.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith(Action<Task<TResult>>, TaskScheduler)
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^> ^ continuationAction, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task<TResult>> continuationAction, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>> * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task(Of TResult)), scheduler As TaskScheduler) As Task
Parameters
Een actie die moet worden uitgevoerd wanneer de bewerking Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task.
Uitzonderingen
De Task<TResult> is verwijderd.
Het continuationAction argument is null.
– of –
Het scheduler argument is null.
Opmerkingen
De geretourneerde Task taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, System::Object ^, TNewResult> ^ continuationFunction, System::Object ^ state, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,object,TNewResult> continuationFunction, object state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, obj, 'NewResult> * obj * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), Object, TNewResult), state As Object, cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgfunctie.
- cancellationToken
- CancellationToken
De CancellationToken taak die wordt toegewezen aan de nieuwe taak.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
Het scheduler argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
De opgegeven CancellationToken is al verwijderd.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
De continuationFunction, wanneer uitgevoerd, moet een Task<TResult>. De voltooiingsstatus van deze taak wordt overgebracht naar de taak die door de Task<TResult>.ContinueWith aanroep wordt geretourneerd.
Zie ook
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in continuationOptions.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, TNewResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,TNewResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, 'NewResult> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), TNewResult), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd volgens de voorwaarde die is opgegeven in continuationOptions.
Wanneer de gemachtigde wordt uitgevoerd, wordt deze voltooide taak doorgegeven als argument.
- cancellationToken
- CancellationToken
De CancellationToken taak die wordt toegewezen aan de nieuwe taak.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
De Task<TResult> is verwijderd.
– of –
De CancellationTokenSource gemaakte cancellationToken is al verwijderd.
Het continuationFunction argument is null.
– of –
Het scheduler argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
De continuationFunction, wanneer uitgevoerd, moet een Task<TResult>.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, System::Object ^, TNewResult> ^ continuationFunction, System::Object ^ state, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,object,TNewResult> continuationFunction, object state, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, obj, 'NewResult> * obj * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), Object, TNewResult), state As Object, scheduler As TaskScheduler) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgfunctie.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
Het scheduler argument is null.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, System::Object ^, TNewResult> ^ continuationFunction, System::Object ^ state, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,object,TNewResult> continuationFunction, object state, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, obj, 'NewResult> * obj * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), Object, TNewResult), state As Object, continuationOptions As TaskContinuationOptions) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgfunctie.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
Het continuationFunction argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
De continuationFunction, wanneer uitgevoerd, moet een Task<TResult>. De voltooiingsstatus van deze taak wordt overgebracht naar de taak die wordt geretourneerd door de aanroep ContinueWith.
Zie ook
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, System::Object ^, TNewResult> ^ continuationFunction, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,object,TNewResult> continuationFunction, object state, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, obj, 'NewResult> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), Object, TNewResult), state As Object, cancellationToken As CancellationToken) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgfunctie.
- cancellationToken
- CancellationToken
De CancellationToken taak die wordt toegewezen aan de nieuwe taak.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
Het continuationFunction argument is null.
De opgegeven CancellationToken is al verwijderd.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions)
Hiermee maakt u een vervolg dat wordt uitgevoerd volgens de voorwaarde die is opgegeven in continuationOptions.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, TNewResult> ^ continuationFunction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,TNewResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, 'NewResult> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), TNewResult), continuationOptions As TaskContinuationOptions) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd volgens de voorwaarde die is opgegeven in continuationOptions.
Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
- continuationOptions
- TaskContinuationOptions
Opties voor wanneer de voortzetting is gepland en hoe deze zich gedraagt. Dit omvat criteria, zoals OnlyOnCanceled, evenals uitvoeringsopties, zoals ExecuteSynchronously.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
De Task<TResult> is verwijderd.
Het continuationFunction argument is null.
Het continuationOptions argument geeft een ongeldige waarde voor TaskContinuationOptions.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
De continuationFunction, wanneer uitgevoerd, moet een Task<TResult>.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken)
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, TNewResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,TNewResult> continuationFunction, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, 'NewResult> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), TNewResult), cancellationToken As CancellationToken) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
- cancellationToken
- CancellationToken
De CancellationToken taak die wordt toegewezen aan de nieuwe taak.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
De Task<TResult> is verwijderd.
– of –
De CancellationTokenSource gemaakte cancellationToken is al verwijderd.
Het continuationFunction argument is null.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object)
Hiermee maakt u een vervolg dat wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, System::Object ^, TNewResult> ^ continuationFunction, System::Object ^ state);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,object,TNewResult> continuationFunction, object state);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, obj, 'NewResult> * obj -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), Object, TNewResult), state As Object) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak en het door de aanroeper opgegeven statusobject als argumenten doorgegeven.
- state
- Object
Een object dat gegevens vertegenwoordigt die moeten worden gebruikt door de vervolgfunctie.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
Het continuationFunction argument is null.
Voorbeelden
In het volgende voorbeeld wordt een keten van vervolgtaken gemaakt. Elke taak biedt de huidige tijd, een DateTime object, voor het statusargument van de ContinueWith(Action<Task,Object>, Object) methode. Elke DateTime waarde vertegenwoordigt het tijdstip waarop de continue taak wordt gemaakt. Elke taak produceert als resultaat een tweede DateTime waarde die het tijdstip aangeeft waarop de taak is voltooid. Nadat alle taken zijn voltooid, worden in het voorbeeld de datum en tijden weergegeven waarop elke vervolgtaak begint en eindigt.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
// Demonstrates how to associate state with task continuations.
class ContinuationState
{
// Simluates a lengthy operation and returns the time at which
// the operation completed.
public static DateTime DoWork()
{
// Simulate work by suspending the current thread
// for two seconds.
Thread.Sleep(2000);
// Return the current time.
return DateTime.Now;
}
static void Main(string[] args)
{
// Start a root task that performs work.
Task<DateTime> t = Task<DateTime>.Run(delegate { return DoWork(); });
// Create a chain of continuation tasks, where each task is
// followed by another task that performs work.
List<Task<DateTime>> continuations = new List<Task<DateTime>>();
for (int i = 0; i < 5; i++)
{
// Provide the current time as the state of the continuation.
t = t.ContinueWith(delegate { return DoWork(); }, DateTime.Now);
continuations.Add(t);
}
// Wait for the last task in the chain to complete.
t.Wait();
// Print the creation time of each continuation (the state object)
// and the completion time (the result of that task) to the console.
foreach (var continuation in continuations)
{
DateTime start = (DateTime)continuation.AsyncState;
DateTime end = continuation.Result;
Console.WriteLine("Task was created at {0} and finished at {1}.",
start.TimeOfDay, end.TimeOfDay);
}
}
}
/* Sample output:
Task was created at 10:56:21.1561762 and finished at 10:56:25.1672062.
Task was created at 10:56:21.1610677 and finished at 10:56:27.1707646.
Task was created at 10:56:21.1610677 and finished at 10:56:29.1743230.
Task was created at 10:56:21.1610677 and finished at 10:56:31.1779883.
Task was created at 10:56:21.1610677 and finished at 10:56:33.1837083.
*/
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks
' Demonstrates how to associate state with task continuations.
Public Module ContinuationState
' Simluates a lengthy operation and returns the time at which
' the operation completed.
Public Function DoWork() As Date
' Simulate work by suspending the current thread
' for two seconds.
Thread.Sleep(2000)
' Return the current time.
Return Date.Now
End Function
Public Sub Main()
' Start a root task that performs work.
Dim t As Task(Of Date) = Task(Of Date).Run(Function() DoWork())
' Create a chain of continuation tasks, where each task is
' followed by another task that performs work.
Dim continuations As New List(Of Task(Of DateTime))()
For i As Integer = 0 To 4
' Provide the current time as the state of the continuation.
t = t.ContinueWith(Function(antecedent, state) DoWork(), DateTime.Now)
continuations.Add(t)
Next
' Wait for the last task in the chain to complete.
t.Wait()
' Display the creation time of each continuation (the state object)
' and the completion time (the result of that task) to the console.
For Each continuation In continuations
Dim start As DateTime = CDate(continuation.AsyncState)
Dim [end] As DateTime = continuation.Result
Console.WriteLine("Task was created at {0} and finished at {1}.",
start.TimeOfDay, [end].TimeOfDay)
Next
End Sub
End Module
' The example displays output like the following:
' Task was created at 10:56:21.1561762 and finished at 10:56:25.1672062.
' Task was created at 10:56:21.1610677 and finished at 10:56:27.1707646.
' Task was created at 10:56:21.1610677 and finished at 10:56:29.1743230.
' Task was created at 10:56:21.1610677 and finished at 10:56:31.1779883.
' Task was created at 10:56:21.1610677 and finished at 10:56:33.1837083.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>)
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, TNewResult> ^ continuationFunction);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,TNewResult> continuationFunction);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, 'NewResult> -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), TNewResult)) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
De Task<TResult> is verwijderd.
Het continuationFunction argument is null.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken
Van toepassing op
ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler)
Hiermee maakt u een vervolg dat asynchroon wordt uitgevoerd wanneer het doel Task<TResult> is voltooid.
public:
generic <typename TNewResult>
System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, TNewResult> ^ continuationFunction, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult>(Func<System.Threading.Tasks.Task<TResult>,TNewResult> continuationFunction, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, 'NewResult> * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'NewResult>
Public Function ContinueWith(Of TNewResult) (continuationFunction As Func(Of Task(Of TResult), TNewResult), scheduler As TaskScheduler) As Task(Of TNewResult)
Type parameters
- TNewResult
Het type resultaat dat door de voortzetting wordt geproduceerd.
Parameters
Een functie die moet worden uitgevoerd wanneer de uitvoering Task<TResult> is voltooid. Wanneer de gemachtigde wordt uitgevoerd, wordt de voltooide taak als argument doorgegeven.
- scheduler
- TaskScheduler
De TaskScheduler taak die moet worden gekoppeld aan de vervolgtaak en moet worden gebruikt voor de uitvoering ervan.
Retouren
Een nieuwe voortzetting Task<TResult>.
Uitzonderingen
De Task<TResult> is verwijderd.
Het continuationFunction argument is null.
– of –
Het scheduler argument is null.
Opmerkingen
De geretourneerde Task<TResult> taak wordt pas gepland voor uitvoering als de huidige taak is voltooid, of deze is voltooid omdat de uitvoering is voltooid, mislukt vanwege een niet-verwerkte uitzondering of vroegtijdig wordt afgesloten omdat deze is geannuleerd.
Zie ook
- TaskScheduler
- Taakparallelbibliotheek (TPL)
- Asynchrone programmering op basis van taken
- taken koppelen met behulp van vervolgtaken