I have the following bit of code -
await Task.WhenAll(TaskList /*List of Task objects*/);
await AnotherAwaitableMethod( );
This works fine and is necessary as AnotherAwaitableMethod
relies on making certain that a task within TaskList
is complete before executing.
However, I would like to be able to say something like
await Task.WhenAll(TaskList).ContinueWith( /*AnotherAwaitableMethod call?*/ );
Is this possible? Am I misunderstanding the purpose of Task.ContinueWith
?
await Task.WhenAll(TaskList /*List of Task objects*/);
await AnotherAwaitableMethod( );
and
await Task.WhenAll(TaskList /*List of Task objects*/).ContinueWith(_ => {AnotherAwaitableMethod();}).Unwrap();
will act almost identically. Using ContinueWith however will give you a lot move power if you use its overloads . One of the main reasons to use ContinueWith is when you want to execute AnotherAwaitableMethod conditionally based on the result of the first task(s) or when you want to control the context using TaskContinuationOptions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.