How to cancel a CancellationToken

前端 未结 4 1729
我在风中等你
我在风中等你 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 21:20

    Spawn CancellationToken instances from a CancellationTokenSource instance and call Cancel on the CTS instance.

    Example: https://msdn.microsoft.com/en-us/library/dd321955(v=vs.110).aspx

    There's also a way to gracefully cancel threads without them firing exceptions, just check the CT for IsCancellationRequested and handle the case yourself. More info: Use of IsCancellationRequested property?

提交回复
热议问题