Is there any way to implement CancelationTokenSource, which allow to aggregate two or more others CancelationToken inside? which allows me to write something like this:
void async Task DoSomeWorkAsync(CancelationToken Token)
{
var cts = AggregatedCancelationTokenSource(Token,
new CancelationTokenSource(TimeSpan.FromSeconds(30)).Token);
//Cancelation occurred:
// when timeout will be expired
// or
// when external Token.IsCancellationRequested will start to return "true"
await DoSomeOtherWorkAsync(cts.Token);
}
Yes, you can use CancellationTokenSource.CreateLinkedTokenSource, from documentation:
Creates a CancellationTokenSource that will be in the canceled state when any of the source tokens are in the canceled state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With