diff --git a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs index 0a781bc..f7267d2 100644 --- a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs @@ -349,12 +349,14 @@ namespace MQTTnet.Client keepAliveSendInterval = _options.KeepAliveSendInterval.Value; } - if (_sendTracker.Elapsed > keepAliveSendInterval) + var waitTime = keepAliveSendInterval - _sendTracker.Elapsed; + if (waitTime <= TimeSpan.Zero) { await SendAndReceiveAsync(new MqttPingReqPacket(), cancellationToken).ConfigureAwait(false); + waitTime = keepAliveSendInterval; } - await Task.Delay(keepAliveSendInterval, cancellationToken).ConfigureAwait(false); + await Task.Delay(waitTime, cancellationToken).ConfigureAwait(false); } } catch (Exception exception)