async void CloseIotHubConnection() { if (!this.ConnectedToHub) { // closure happened before IoT Hub connection was established or it was initiated due to disconnect return; } try { this.publishProcessor.Complete(); this.publishPubAckProcessor.Complete(); this.publishPubRecProcessor.Complete(); this.pubRelPubCompProcessor.Complete(); await Task.WhenAll( this.publishProcessor.Completion, this.publishPubAckProcessor.Completion, this.publishPubRecProcessor.Completion, this.pubRelPubCompProcessor.Completion); IDeviceClient hub = this.iotHubClient; this.iotHubClient = null; await hub.DisposeAsync(); } catch (Exception ex) { MqttIotHubAdapterEventSource.Log.Info("Failed to close IoT Hub Client cleanly.", ex.ToString()); } }
async void ShutdownOnReceiveError(IChannelHandlerContext context, string exception) { this.publishPubAckProcessor.Abort(); this.publishProcessor.Abort(); this.publishPubRecProcessor.Abort(); this.pubRelPubCompProcessor.Abort(); IDeviceClient hub = this.iotHubClient; if (hub != null) { this.iotHubClient = null; try { await hub.DisposeAsync(); } catch (Exception ex) { MqttIotHubAdapterEventSource.Log.Info("Failed to close IoT Hub Client cleanly.", ex.ToString()); } } ShutdownOnError(context, "Receive", exception); }