コード例 #1
0
 public async Task DisconnectAsync()
 {
     try
     {
         await _client.DisconnectAsync();
     }
     catch (Exception ex)
     {
         _logger.LogError("DisconnectAsync error:\n" + ex.ToString());
     }
 }
コード例 #2
0
 public async Task DisconnectAsync()
 {
     if (client == null)
     {
         return;
     }
     if (!client.IsConnected)
     {
         return;
     }
     await client.DisconnectAsync();
 }
コード例 #3
0
 private void ConnectButton_Click(object sender, RoutedEventArgs e)
 {
     if (mqttClient.IsConnected)
     {
         Task.Run(async() =>
         {
             try
             {
                 await mqttClient.DisconnectAsync();
             }
             catch { }
         });
     }
     else
     {
         MqttIsConnected = true;
         var temp = new MqttClientOptionsBuilder()
                    .WithClientId(Tools.Global.setting.mqttClientID)
                    .WithTcpServer(Tools.Global.setting.mqttServer, Tools.Global.setting.mqttPort)
                    .WithCredentials(Tools.Global.setting.mqttUser, Tools.Global.setting.mqttPassword)
                    .WithKeepAlivePeriod(new TimeSpan(0, 0, Tools.Global.setting.mqttKeepAlive));
         if (Tools.Global.setting.mqttTLS)
         {
             temp.WithTls();
         }
         if (Tools.Global.setting.mqttCleanSession)
         {
             temp.WithCleanSession();
         }
         var options = temp.Build();
         Task.Run(async() =>
         {
             try
             {
                 await mqttClient.ConnectAsync(options, CancellationToken.None);
             }
             catch { }
         });
     }
 }
コード例 #4
0
ファイル: MQTTnetClient.cs プロジェクト: davilu/edge-test
 public Task DisconnectAsync(CancellationToken cancellationToken)
 {
     client.UseConnectedHandler((Action <MqttClientConnectedEventArgs>)null);
     client.UseDisconnectedHandler((Action <MqttClientDisconnectedEventArgs>)null);
     return(client.DisconnectAsync(new MqttClientDisconnectOptions(), cancellationToken));
 }