How to cancel a CancellationToken

前端 未结 4 1731
我在风中等你
我在风中等你 2021-02-06 20:30

I start a task, that start other tasks and so forth.
Given that tree, if any task fails the result of the whole operation is useless. I\'m considering using cancellation tok

4条回答
  •  [愿得一人]
    2021-02-06 20:58

    As an extension of the answers provided so far, if you want to have both a CancellationToken instance provided to your methods, and cancel internally, you should examine CancellationTokenSource.CreateLinkedTokenSource. In essence this will cancel either when cts.Cancel() is called, or one of its supplied tokens is.

提交回复
热议问题