Question: Is there a way to associate a CancellationToken
with the Task
returned from an async
method?
Generally,
I think the design works well for the common case: if any child operations are cancelled, then the cancellation propagates to the parent (the most common case is that the parent and child share cancellation tokens).
If you want different semantics, you can catch
the OperationCanceledException
in your async
method and throw an exception that fits the semantics you need. If you want to use these semantics repeatedly, an extension method for Task
should fit the bill.