async Task SendDataAsync(string connectionString) { var list = await CacheHelper.GetSimulatedSensorListFromCacheAsync(_cache); DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(connectionString); if (deviceClient == null) { await FeedbackHelper.Channel.SendMessageAsync("Failed to connect to Azure IoT Hub.", MessageType.Info); return; } while (CacheHelper.IsInSendingDataState(_cache)) { await FeedbackHelper.Channel.SendMessageAsync("Sending Data...", MessageType.Info); foreach (SimulatedSensor sensor in list) { await IoTHubHelper.SendEvent(deviceClient, sensor); } await Task.Delay(TimeSpan.FromSeconds(ConfigHelper.Config.parameters.SimulatorTimer)); } await FeedbackHelper.Channel.SendMessageAsync("Sending data stopped.", MessageType.Info); }