Compared to the preceding code for class RulyCanceler, I wanted to run code using CancellationTokenSource.
How do I use it as mentioned in Cancellation
@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
throwOnFirstExceptionis true, an exception will immediately propagate out of the call to Cancel, preventing the remaining callbacks and cancelable operations from being processed. IfthrowOnFirstExceptionis false, this overload will aggregate any exceptions thrown into anAggregateException, 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.