我需要在特定时间触发托管服务,例如。每天13:00。我的典型 ExecuteAsync 方法似乎是这样的:
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var interval = _configuration.IntervalInSeconds * 1000;
while (!stoppingToken.IsCancellationRequested)
{
// some job
await Task
.Delay(interval, stoppingToken);
}
}
Run Code Online (Sandbox Code Playgroud)
例如,当应用程序启动时,会调用 executeAsync 方法,然后每分钟都会发生一些操作。现在我必须只在特定时间执行这样的操作。有什么方法可以实现这种行为吗?除了粗略计算下一次触发时间之外,我的问题还有什么解决方案吗??谢谢你的帮助。