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
Canceledstate in these scenarios:
- [...]
- When the continuation was passed a
System.Threading.CancellationTokenas an argument and theIsCancellationRequestedproperty of the token istruebefore the continuation runs. In such a case, the continuation does not start and it transitions to theCanceledstate.
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?