File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
nanoFramework.Aws.IoTCore.Devices Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ public enum QoSLevel
5151 private readonly X509Certificate2 _clientCert ; //Combined ClientRsaSha256Crt and ClientRsaKey
5252 private readonly X509Certificate _awsRootCACert ;
5353
54- private M2Mqtt . MqttClient _mqttc ;
54+ private M2Mqtt . MqttClient _mqttc = null ;
5555 private readonly ConnectorState _mqttBrokerStatus = new ConnectorState ( ) ;
5656 private readonly ArrayList _waitForConfirmation = new ArrayList ( ) ;
5757 private readonly object _lock = new object ( ) ;
@@ -243,18 +243,22 @@ private void TimerCallbackReconnect(object state)
243243 /// </summary>
244244 public void Close ( )
245245 {
246- if ( _mqttc . IsConnected )
246+ if ( _mqttc != null )
247247 {
248- _mqttc . Unsubscribe ( new [ ] {
248+ if ( _mqttc . IsConnected )
249+ {
250+ _mqttc . Unsubscribe ( new [ ] {
249251 $ "{ _deviceMessageTopic } /#",
250252 $ "{ _shadowTopic } /#",
251253 } ) ;
254+ }
252255 _mqttc . Disconnect ( ) ;
256+ _mqttc . Close ( ) ;
253257 // Make sure all get disconnected, cleared (TODO: 1 second arbitrary value specified)
254258 Thread . Sleep ( 1000 ) ;
255259 }
256260
257- _timerTokenRenew . Dispose ( ) ;
261+ _timerTokenRenew ? . Dispose ( ) ;
258262 }
259263
260264 /// <summary>
You can’t perform that action at this time.
0 commit comments