コード例 #1
0
ファイル: MqttClient.cs プロジェクト: zhouhongjie/MQTTnet
        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);
                }
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: MqttClientExtensions.cs プロジェクト: zz110/MQTTnet
        public static Task DisconnectAsync(this IMqttClient client, MqttClientDisconnectOptions options)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.DisconnectAsync(options, CancellationToken.None));
        }
コード例 #4
0
 public static Task DisconnectAsync(this IMqttClient client, MqttClientDisconnectOptions options)
 {
     return(client.DisconnectAsync(options, CancellationToken.None));
 }