async Task ReceiveMessages(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { var message = await _lowLevelClient.ReceiveAsync(cancellationToken).ConfigureAwait(false); if (cancellationToken.IsCancellationRequested) { return; } if (message == null) { continue; } if (!_messageDispatcher.TryHandleReceivedMessage(message)) { if (!await _observationManager.TryHandleReceivedMessage(message).ConfigureAwait(false)) { _logger.Trace(nameof(CoapClient), "Received an unexpected message ({0}).", message.Id); } } } catch (OperationCanceledException) { } catch (Exception exception) { _logger.Error(nameof(CoapClient), exception, "Error while receiving messages."); } } }
async Task ReceiveMessages(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { var message = await _lowLevelClient.ReceiveAsync(cancellationToken).ConfigureAwait(false); if (!_messageDispatcher.TryDispatch(message)) { if (!await TryHandleObservedMessage(message).ConfigureAwait(false)) { await DeregisterObservation(message).ConfigureAwait(false); } } } catch (Exception exception) { _logger.Error(nameof(CoapClient), exception, "Error while receiving message."); } } }