public async Task DisconnectAsync(MqttClientDisconnectOptions options, CancellationToken cancellationToken) { if (options is null) { throw new ArgumentNullException(nameof(options)); } ThrowIfDisposed(); try { _cleanDisconnectInitiated = true; if (IsConnected) { var disconnectPacket = _adapter.PacketFormatterAdapter.DataConverter.CreateDisconnectPacket(options); await SendAsync(disconnectPacket, cancellationToken).ConfigureAwait(false); } } finally { if (!DisconnectIsPending()) { await DisconnectInternalAsync(null, null, null).ConfigureAwait(false); } } }
public async Task DisconnectAsync(MqttClientDisconnectOptions options, CancellationToken cancellationToken) { if (options is null) { throw new ArgumentNullException(nameof(options)); } ThrowIfDisposed(); var clientWasConnected = IsConnected; if (DisconnectIsPendingOrFinished()) { return; } try { _disconnectReason = MqttClientDisconnectReason.NormalDisconnection; _cleanDisconnectInitiated = true; if (clientWasConnected) { var disconnectPacket = _adapter.PacketFormatterAdapter.DataConverter.CreateDisconnectPacket(options); await SendAsync(disconnectPacket, cancellationToken).ConfigureAwait(false); } } finally { await DisconnectCoreAsync(null, null, null, clientWasConnected).ConfigureAwait(false); } }
public static Task DisconnectAsync(this IMqttClient client, MqttClientDisconnectOptions options) { if (client == null) { throw new ArgumentNullException(nameof(client)); } return(client.DisconnectAsync(options, CancellationToken.None)); }
public static Task DisconnectAsync(this IMqttClient client, MqttClientDisconnectOptions options) { return(client.DisconnectAsync(options, CancellationToken.None)); }