protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); alertChecker.CheckAndRaiseAlertIfNeeded(stoppingToken); await Task.Delay(5000, stoppingToken); } }
private void StartAlerting(IAlertChecker alertChecker, CancellationToken cancellationToken) { alertChecker.OnTemperatureTooLowAlert += AlertCheckingScheduler_OnTemperatureTooLowAlert; new Task(() => { Logger.LogInformation("Starting alert detection."); while (!cancellationToken.IsCancellationRequested) { alertChecker.CheckAndRaiseAlertIfNeeded(cancellationToken); WaitForNextCycle(cancellationToken, 360); } }, TaskCreationOptions.LongRunning).Start(); }