I have that situation:
private Task LongRunningTask = /* Something */;
private void DoSomethingMore(Task previousTask) { }
public Task IndependentlyCancelableSuccessorTask(CancellationToken cancellationToken)
{
return LongRunningTask.ContinueWith(DoSomethingMore, cancellationToken);
}
In particular, the behavior that interests me here is detailed in MSDN's page about Continuation Tasks in the following terms:
A continuation goes into the
Canceled
state in these scenarios:
- [...]
- When the continuation was passed a
System.Threading.CancellationToken
as an argument and theIsCancellationRequested
property of the token istrue
before the continuation runs. In such a case, the continuation does not start and it transitions to theCanceled
state.
The code above works. However, I am in the process of converting as many as possible of my continuations to using the await
keyword.
Is there an equivalent using await
that would allow the continuation to be canceled before the awaited task completes?