Home > database >  What's the difference between CancellationTokenSource constructor delay parameter and CancelAft
What's the difference between CancellationTokenSource constructor delay parameter and CancelAft

Time:04-10

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?

CodePudding user response:

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

  • Related