private async Task PollDht11Continuously() { try { using var dht11 = new Dht11(24); while (!_applicationLifetime.ApplicationStopping.IsCancellationRequested) { var humidity = dht11.Humidity; var temperature = dht11.Temperature; if (dht11.IsLastReadSuccessful) { _logger.LogInformation($"H = {humidity}, T = {temperature}"); _eventHub.PostTemperatureMeasurement(new TemperatureMeasurementMessage(temperature.DegreesCelsius)); await Task.Delay(10000); } else { _logger.LogInformation("Read failed."); await Task.Delay(2000); } } } catch (Exception ex) { _logger.LogError(ex, "Unexpected DHT11 read failure."); } }