Improve PingAsync timeout handling.

This commit is contained in:
Christian
2022-09-14 14:17:59 +02:00
parent d4dad4860a
commit d23bbf7bf3
6 changed files with 496 additions and 444 deletions
+2 -4
View File
@@ -321,14 +321,12 @@ public static class Client_Connection_Samples
{
try
{
// This code will also do the very first connect! So no call to _ConnectAsync_ is required
// in the first place.
if (!mqttClient.IsConnected)
// This code will also do the very first connect! So no call to _ConnectAsync_ is required in the first place.
if (!await mqttClient.TryPingAsync())
{
await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
// Subscribe to topics when session is clean etc.
Console.WriteLine("The MQTT client is connected.");
}
}