public async Task ConnectAsync(bool isDesiredPropertiesCallbackEnable, TransportType protocol = TransportType.Mqtt) { deviceClient = Microsoft.Azure.Devices.Client.DeviceClient.CreateFromConnectionString(connectionString, protocol); if (isDesiredPropertiesCallbackEnable && (protocol == TransportType.Mqtt)) { await deviceClient.SetDesiredPropertyUpdateCallbackAsync(DesiredPropertyUpdate, this); } if (protocol == TransportType.Mqtt) { await deviceClient.SetMethodDefaultHandlerAsync(MethodHandler, this); } await deviceClient.OpenAsync(); ReceiveMessages(); }