“timer + Task.Run” vs “while loop + Task.Delay” in asp.net core hosted service
问题 I have a requirement that background service should run Process method every day at 0:00 a.m. So, one of my team member wrote the following code: public class MyBackgroundService : IHostedService, IDisposable { private readonly ILogger _logger; private Timer _timer; public MyBackgroundService(ILogger<MyBackgroundService> logger) { _logger = logger; } public void Dispose() { _timer?.Dispose(); } public Task StartAsync(CancellationToken cancellationToken) { TimeSpan interval = TimeSpan