You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, the documentation for how to auto reconnect, when connection fails, is confusing. I'd appreciate it if I can get some clarification on the questions below.
First of all, the Wiki is referencing a method that no longer exists, which will lead developers to the samples below.
This approach has a risk of dead locks! Consider using the timer approach (see sample).
But the comment in MqttClient.cs, where the Disconnected event is raised, says that it's wrapped in a Task.Run(...) to avoid dead-locks.
Q1) Is running in a separate thread not enough and it may end up in a dead-lock anyway? or should the samples be updated and that comment removed to avoid confusion?
The sample recommends calling TryPingAsync in a loop which seems incorrect after looking at the code in MqttClient.cs since the client internally maintains a keep alive loop where it pings the server and updates the connection status (IsConnected) accordingly. And it does it in a way that's better than a simple loop with TryPingAsync because it takes into consideration whether packets have been exchanged succesfully and thus avoids the extra pings.
And more to this point, when looking at ManagedMqttClient which has a timer loop, it doesn't call Ping at all, but instead checks IsConnected
Q2) Is Reconnect_Using_Timer sample misleading and inefficient or have I missed something?
The text was updated successfully, but these errors were encountered:
Hi, the documentation for how to auto reconnect, when connection fails, is confusing. I'd appreciate it if I can get some clarification on the questions below.
First of all, the Wiki is referencing a method that no longer exists, which will lead developers to the samples below.
Reconnect_Using_Event Sample
The sample states:
But the comment in MqttClient.cs, where the Disconnected event is raised, says that it's wrapped in a
Task.Run(...)
to avoid dead-locks.Q1) Is running in a separate thread not enough and it may end up in a dead-lock anyway? or should the samples be updated and that comment removed to avoid confusion?
Reconnect_Using_Timer Sample
The sample recommends calling
TryPingAsync
in a loop which seems incorrect after looking at the code in MqttClient.cs since the client internally maintains a keep alive loop where it pings the server and updates the connection status (IsConnected
) accordingly. And it does it in a way that's better than a simple loop withTryPingAsync
because it takes into consideration whether packets have been exchanged succesfully and thus avoids the extra pings.And more to this point, when looking at
ManagedMqttClient
which has a timer loop, it doesn't callPing
at all, but instead checksIsConnected
Q2) Is
Reconnect_Using_Timer
sample misleading and inefficient or have I missed something?The text was updated successfully, but these errors were encountered: