protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogDebug("Service is starting."); stoppingToken.Register(() => _logger.LogDebug("Service stop request received.")); _logger.LogInformation($"Startup delay configured: {_options.Value.StartupDelaySeconds} sec"); await Task.Delay(millisecondsDelay : _options.Value.StartupDelaySeconds * 1000, cancellationToken : stoppingToken).ConfigureAwait(false); var ids = _options.Value.GasStations.Select(x => x.StationId).ToArray(); while (!stoppingToken.IsCancellationRequested) { var data = await _api.GetPriceListAsync(ids).ConfigureAwait(false); await PushInfoToOpenhabAsync(data, stoppingToken).ConfigureAwait(false); var nextdelay = GenerateNextDelay(); _logger.LogInformation($"Next update in : {nextdelay/1000} sec"); await Task.Delay(millisecondsDelay : nextdelay, cancellationToken : stoppingToken).ConfigureAwait(false); } await Task.Delay(1000).ConfigureAwait(false); _logger.LogDebug("Service is finished."); int GenerateNextDelay() { return((_options.Value.UpdateDelaySeconds + _rand.Next(-_delayvar, _delayvar)) * 1000); } }