diff --git a/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttV1Transport.cs b/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttV1Transport.cs index 454b3d5..f0604dc 100644 --- a/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttV1Transport.cs +++ b/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttV1Transport.cs @@ -238,15 +238,15 @@ private async Task ResendFailedMessages(CancellationToken cancellationToken = de Trace.WriteLine("Resending stored messages in progress."); _resendingInProgress = true; + if (_client == null || _failedMessageStorage == null) + { + Console.WriteLine("Client or failed message storage is null."); + _resendingInProgress = false; + return; + } + try { - if (_client == null || _failedMessageStorage == null) - { - Trace.WriteLine("Client or failed message storage is null."); - _resendingInProgress = false; - return; - } - await WaitForPendingMessagesToClear(_client); var storedMessages = await _failedMessageStorage.LoadQueuedMessagesAsync(); @@ -263,7 +263,6 @@ private async Task ResendFailedMessages(CancellationToken cancellationToken = de } await WaitForPendingMessagesToClear(_client); - await ResendFailedMessages(cancellationToken); } catch (OperationCanceledException) { @@ -274,6 +273,8 @@ private async Task ResendFailedMessages(CancellationToken cancellationToken = de _resendingInProgress = false; Trace.WriteLine("Resending stored messages finished."); } + + await ResendFailedMessages(cancellationToken); } private static async Task WaitForPendingMessagesToClear(IManagedMqttClient _client)