I am writing some internal framework code and at some point I want to throw an MyCustomException when TaskCanceledException happens, because I want to add the delay configured for the CancellationToken to the message. That is, in:
var cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.CancelAfter(cancellationTokenDelay); return cancellationTokenSource.Token; I want to get the value passed to the CancelAfter method. The problem is: CancellationToken does not seem to expose this information. Is there any trick to get it?
(I already considered timing the operation with a Stopwatch, but I am looking for a more elegant alternative).