SetMethodHandlerAsync connection still valid

Stephens, Mike 1 Reputation point
2020-08-18T12:29:18.677+00:00

The Azure IoT SDK allows a method handler to be assigned after setting up a connection string to the Azure IoT hub (such as below).

       // Create the device client
       deviceClient = DeviceClient.CreateFromConnectionString(hubConnect,
                                                                                                    Microsoft.Azure.Devices.Client.TransportType.Mqtt_WebSocket_Only);

       // Register the delegate for the print job available direct method
       deviceClient.SetMethodHandlerAsync("ClientProcess",
                                                                    ClientProcess,
                                                                    null).Wait();

After a random interval, the client process is unable to receive any more notificaitons from the IoT hub. How can the client process determine if the connection to the IoT hub is still valid and able to receive messages when the method handler is set?

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,128 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
208 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Roman Kiss 2,246 Reputation points
    2020-08-18T14:18:10.883+00:00

    Register a new delegate for the connection status changed callback:

    public void SetConnectionStatusChangesHandler(ConnectionStatusChangesHandler statusChangesHandler);
    

    where the delegate has the following signature:

    public delegate void ConnectionStatusChangesHandler(ConnectionStatus status, ConnectionStatusChangeReason reason);