anon
anon

Reputation:

CancellationTokensource with delay/timeout - differentiate afterwards what happened?

When initializing a CancellationTokenSource with a delay value set, is it possible to check afterwards what exactly happened - whether the timeout time was reached or whether .Cancel(..) was called explicitely?

Right now the OperationCanceledException that occurs after the delay seems to have no such indicator, but maybe I am missing it somehow.

Upvotes: 1

Views: 791

Answers (1)

svick
svick

Reputation: 244827

One way to work around that would be to have two separate CancellationTokenSources: one for the delay and one for manual cancellation. You would then combine them into one using CancellationTokenSource.CreateLinkedTokenSource() and use that. When the combined token source is canceled, you can check the two original token sources to see what happened.

Upvotes: 3

Related Questions