Browse Source

Fix issues with disconnected event

release/3.x.x
Christian Kratky 7 years ago
parent
commit
7de1634a36
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      MQTTnet.Core/Client/MqttClient.cs

+ 6
- 5
MQTTnet.Core/Client/MqttClient.cs View File

@@ -42,14 +42,14 @@ namespace MQTTnet.Core.Client


try try
{ {
MqttTrace.Verbose(nameof(MqttClient), "Trying to connect with server.");
await _adapter.ConnectAsync(_options.DefaultCommunicationTimeout, _options).ConfigureAwait(false);
MqttTrace.Verbose(nameof(MqttClient), "Connection with server established.");

_cancellationTokenSource = new CancellationTokenSource(); _cancellationTokenSource = new CancellationTokenSource();
_latestPacketIdentifier = 0; _latestPacketIdentifier = 0;
_packetDispatcher.Reset(); _packetDispatcher.Reset();


MqttTrace.Verbose(nameof(MqttClient), "Trying to connect with server.");
await _adapter.ConnectAsync(_options.DefaultCommunicationTimeout, _options).ConfigureAwait(false);
MqttTrace.Verbose(nameof(MqttClient), "Connection with server established.");

StartReceivePackets(_cancellationTokenSource.Token); StartReceivePackets(_cancellationTokenSource.Token);


var connectPacket = new MqttConnectPacket var connectPacket = new MqttConnectPacket
@@ -69,12 +69,13 @@ namespace MQTTnet.Core.Client
} }


MqttTrace.Verbose(nameof(MqttClient), "MQTT connection with server established."); MqttTrace.Verbose(nameof(MqttClient), "MQTT connection with server established.");
Connected?.Invoke(this, EventArgs.Empty);


if (_options.KeepAlivePeriod != TimeSpan.Zero) if (_options.KeepAlivePeriod != TimeSpan.Zero)
{ {
StartSendKeepAliveMessages(_cancellationTokenSource.Token); StartSendKeepAliveMessages(_cancellationTokenSource.Token);
} }

Connected?.Invoke(this, EventArgs.Empty);
} }
catch (Exception) catch (Exception)
{ {


Loading…
Cancel
Save