diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs index 5a392c30..ffb86394 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs @@ -45,6 +45,7 @@ namespace MQTTnet.ManagedClient public event EventHandler Disconnected; public event EventHandler ApplicationMessageReceived; public event EventHandler ApplicationMessageProcessed; + public event EventHandler SynchronizingSubscriptionsFailed; public async Task StartAsync(IManagedMqttClientOptions options) { @@ -309,13 +310,22 @@ namespace MQTTnet.ManagedClient try { - await _mqttClient.SubscribeAsync(subscriptions).ConfigureAwait(false); - await _mqttClient.UnsubscribeAsync(unsubscriptions).ConfigureAwait(false); + if (subscriptions.Any()) + { + await _mqttClient.SubscribeAsync(subscriptions).ConfigureAwait(false); + } + + if (unsubscriptions.Any()) + { + await _mqttClient.UnsubscribeAsync(unsubscriptions).ConfigureAwait(false); + } } catch (Exception exception) { - _logger.Warning(exception, "Synchronizing subscriptions failed"); + _logger.Warning(exception, "Synchronizing subscriptions failed."); _subscriptionsNotPushed = true; + + SynchronizingSubscriptionsFailed?.Invoke(this, EventArgs.Empty); } }