public void Cleanup()
        {
            foreach (var mp in _mqttPublisherClientsByPublisherName)
            {
                var mqttPublisherClient = mp.Value;
                mqttPublisherClient.DisconnectAsync().GetAwaiter().GetResult();
                mqttPublisherClient.Dispose();
            }
            _mqttPublisherClientsByPublisherName.Clear();

            foreach (var mqttSubscriber in _mqttSubscriberClients)
            {
                mqttSubscriber.DisconnectAsync().GetAwaiter().GetResult();
                mqttSubscriber.Dispose();
            }
            _mqttSubscriberClients.Clear();

            _mqttServer.StopAsync().GetAwaiter().GetResult();
            _mqttServer.Dispose();
            _mqttServer = null;
        }
        public async Task Cleanup()
        {
            foreach (var mqttClient in _mqttSubscriberClients)
            {
                await mqttClient.DisconnectAsync();

                mqttClient.ApplicationMessageReceivedAsync -= HandleApplicationMessageReceivedAsync;
                mqttClient.Dispose();
            }

            foreach (var pub in _mqttPublisherClientsByPublisherName)
            {
                var mqttClient = pub.Value;
                await mqttClient.DisconnectAsync();

                mqttClient.Dispose();
            }

            await _mqttServer.StopAsync();

            _mqttServer.Dispose();
        }
Exemple #3
0
 public void Cleanup()
 {
     _mqttClient.DisconnectAsync().GetAwaiter().GetResult();
     _mqttServer.StopAsync().GetAwaiter().GetResult();
     _mqttServer.Dispose();
 }