コード例 #1
0
 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);
     }
 }
コード例 #2
0
        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();
        }