How to use the CancellationToken property?

前端 未结 5 1735
-上瘾入骨i
-上瘾入骨i 2020-11-28 05:07

Compared to the preceding code for class RulyCanceler, I wanted to run code using CancellationTokenSource.

How do I use it as mentioned in Cancellation

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 05:14

    @BrainSlugs83

    You shouldn't blindly trust everything posted on stackoverflow. The comment in Jens code is incorrect, the parameter doesn't control whether exceptions are thrown or not.

    MSDN is very clear what that parameter controls, have you read it? http://msdn.microsoft.com/en-us/library/dd321703(v=vs.110).aspx

    If throwOnFirstException is true, an exception will immediately propagate out of the call to Cancel, preventing the remaining callbacks and cancelable operations from being processed. If throwOnFirstException is false, this overload will aggregate any exceptions thrown into an AggregateException, such that one callback throwing an exception will not prevent other registered callbacks from being executed.

    The variable name is also wrong because Cancel is called on CancellationTokenSource not the token itself and the source changes state of each token it manages.

提交回复
热议问题