private void MessageDistributor() { Boolean threadOk = true; while (_connected && threadOk) { if (_messageDistributorThreadTokenSource.IsCancellationRequested) { return; } try { HTSMessage response = _receivedMessagesQueue.Dequeue(); if (response.containsField("seq")) { int seqNo = response.getInt("seq"); if (_responseHandlers.ContainsKey(seqNo)) { HTSResponseHandler currHTSResponseHandler = _responseHandlers[seqNo]; if (currHTSResponseHandler != null) { _responseHandlers.Remove(seqNo); currHTSResponseHandler.handleResponse(response); } } else { _logger.LogCritical("[TVHclient] HTSConnectionAsync.MessageDistributor: HTSResponseHandler for seq = '{seq}' not found", seqNo); } } else { // auto update messages if (_listener != null) { _listener.onMessage(response); } } } catch (Exception ex) { threadOk = false; if (_listener != null) { _listener.onError(ex); } else { _logger.LogError(ex, "[TVHclient] HTSConnectionAsync.MessageBuilder: exception caught, but no error listener is configured"); } } } }
private void MessageDistributor() { Boolean threadOk = true; while (_connected && threadOk) { try { HTSMessage response = _receivedMessagesQueue.Dequeue(); if (response.containsField("seq")) { int seqNo = response.getInt("seq"); if (_responseHandlers.ContainsKey(seqNo)) { HTSResponseHandler currHTSResponseHandler = _responseHandlers[seqNo]; if (currHTSResponseHandler != null) { _responseHandlers.Remove(seqNo); currHTSResponseHandler.handleResponse(response); } } else { _logger.Fatal("[TVHclient] MessageDistributor: HTSResponseHandler for seq = '" + seqNo + "' not found!"); } } else { // auto update messages if (_listener != null) { _listener.onMessage(response); } } } catch (ThreadAbortException) { threadOk = false; Thread.ResetAbort(); } catch (Exception ex) { if (_listener != null) { _listener.onError(ex); } else { _logger.ErrorException("[TVHclient] MessageBuilder caught exception : {0} but no error listener is configured!!!", ex, ex.ToString()); } } } }