CancellationToken: Make it possible to provide a way to tell whether the cancellation came from a timeout or due to being 'manually' cancelled #110461
Unanswered
ksidirop-laerdal
asked this question in
Ideas
Replies: 2 comments 7 replies
-
You can work around this using multiple CTS a = new CTS(TimeSpan.FromX(1234)); // for a timer
CTS b = new CTS(); // for manual cancellations
using CTS linked = CTS.CreateLinkedCToken(a.Token, b.Token); // don't ever touch this one
CToken token = linked.Token; // use this one in your code Then, only manually cancel |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently there is no way to tell why a cancellation-token requested a cancel from the exceptions it throws. I guess it's too late to change the behavior of it in methods like .WaitAsync() to have it throw a TimeoutException.
If it's not too much of a hassle would it be possible to introduce a new property ala
or something to that effect to help out when we need to figure out the cause?
PS: I'm aware of the technique that gets thing to work at the caller's level using linked-tokens and I do use it but it has a fundamental drawback on a different department:
If you try to develop a generic library that aspires to handle timeouts on tasks in an agnostic manner then you don't have access to the source-token(s) - you only have access to the single token being passed down to your method as a parameter and it doesn't make sense to support passing down 2 tokens as parameters just to cater to the 2-source-tokens-workaround (the API surface of the library would look ... baroque to say the least)
This is the motivation behind this feature request.
Beta Was this translation helpful? Give feedback.
All reactions