I've written a simple debouncer for use with ASP.NET Core 5 (to detect changes to config files). This will be used within the Startup
class. It works well.
However I get an analyzer warning:
Do not create tasks without passing a TaskScheduler csharp(CA2008)
The problem code:
Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith(
task => someAction(),
cancellationToken
);
Which of the following I should use, and how do they differ?
Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith(
task => someAction(),
cancellationToken,
TaskContinuationOptions.None,
TaskScheduler.FromCurrentSynchronizationContext() // <---
);
Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith(
task => someAction(),
cancellationToken,
TaskContinuationOptions.None,
TaskScheduler.Default // <---
);