Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between CancellationTokenSource constructor delay parameter and CancelAfter Method

Given these two approaches

var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1));
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromMinutes(1));

Is there any real difference in behaviour?

The only slight of information is on MS docs but it's not clear since quoting

Subsequent calls to CancelAfter will reset the delay for this CancellationTokenSource, if it has not been canceled already.

So I guess it resets it but does it have any other action regardles?

like image 262
Azelski Avatar asked Jan 25 '26 13:01

Azelski


1 Answers

According to the source, nothing. They both assign to m_timer

like image 190
Daniel A. White Avatar answered Jan 28 '26 03:01

Daniel A. White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!