private async Task ReadChannelAsync() { try { _logger.LogConsumerLowLevelTrace(Consumer, "Starting channel processing loop..."); while (!_readCancellationTokenSource.IsCancellationRequested) { await ReadChannelOnceAsync().ConfigureAwait(false); } } catch (OperationCanceledException) { // Ignore _logger.LogConsumerLowLevelTrace(Consumer, "Exiting channel processing loop (operation canceled)."); } catch (Exception ex) { if (ex is not ConsumerPipelineFatalException) { _logger.LogConsumerFatalError(Consumer, ex); } IsReading = false; _readTaskCompletionSource.TrySetResult(false); await _mqttClientWrapper.Consumer !.DisconnectAsync().ConfigureAwait(false); } IsReading = false; _readTaskCompletionSource.TrySetResult(true); _logger.LogConsumerLowLevelTrace(Consumer, "Exited channel processing loop."); }