浏览代码

Add handlers to variable before using to avoid NullRefExceptions.

release/3.x.x
Christian 5 年前
父节点
当前提交
09718a00e7
共有 1 个文件被更改,包括 12 次插入7 次删除
  1. +12
    -7
      Source/MQTTnet/Client/MqttClient.cs

+ 12
- 7
Source/MQTTnet/Client/MqttClient.cs 查看文件

@@ -100,12 +100,14 @@ namespace MQTTnet.Client

_logger.Info("Connected.");

Connected?.Invoke(this, new MqttClientConnectedEventArgs(authenticateResult));
if(ConnectedHandler != null)
var connectedHandler = ConnectedHandler;
if (connectedHandler != null)
{
await ConnectedHandler.HandleConnectedAsync(new MqttClientConnectedEventArgs(authenticateResult));
await connectedHandler.HandleConnectedAsync(new MqttClientConnectedEventArgs(authenticateResult)).ConfigureAwait(false);
}

// TODO: Remove!
Connected?.Invoke(this, new MqttClientConnectedEventArgs(authenticateResult));

return authenticateResult;
}
@@ -268,11 +270,14 @@ namespace MQTTnet.Client
_cleanDisconnectInitiated = false;

_logger.Info("Disconnected.");
Disconnected?.Invoke(this, new MqttClientDisconnectedEventArgs(clientWasConnected, exception));
if(DisconnectedHandler != null)

var disconnectedHandler = DisconnectedHandler;
if (disconnectedHandler != null)
{
await DisconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception));
await disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception)).ConfigureAwait(false);
}

Disconnected?.Invoke(this, new MqttClientDisconnectedEventArgs(clientWasConnected, exception));
}
}



正在加载...
取消
保存