public async void ReceiveMessageAsync()

in Hands-on lab/lab-files/starter-project/SmartMeterSimulator/Sensor.cs [113:151]


        public async void ReceiveMessageAsync()
        {
            if (DeviceClient == null)
                return;

            try
            {
                Message receivedMessage = await DeviceClient?.ReceiveAsync();
                if (receivedMessage == null)
                {
                    ReceivedMessage = null;
                    return;
                }

                //TODO: 10.Set the received message for this sensor to the string value of the message byte array
                //ReceivedMessage = ...
                if (double.TryParse(ReceivedMessage, out var requestedTemperature))
                {
                    ReceivedTemperatureSetting = requestedTemperature;
                }
                else
                {
                    ReceivedTemperatureSetting = null;
                }

                // Send acknowledgement to IoT Hub that the has been successfully processed.
                // The message can be safely removed from the device queue. If something happened
                // that prevented the device app from completing the processing of the message,
                // IoT Hub delivers it again.

                //TODO: 11.Send acknowledgement to IoT hub that the message was processed
                //await DeviceClient?...
            }
            catch (Exception)
            {
                // The device client is null, likely due to it being disconnected since this method was called.
                System.Diagnostics.Debug.WriteLine("The DeviceClient is null. This is likely due to it being disconnected since the ReceiveMessageAsync message was called.");
            }
        }