public void ThreadMQPublishServer() { try { using (PublisherSocket publishSocket = new PublisherSocket()) { publishSocket.Bind(MQConfig.PublishServer); try { while (!_cancellationTokenSource.IsCancellationRequested) { KeyData item; if (MQPublishQueue.TryTake(out item)) { publishSocket.PublisherSend(item); } } } catch (TerminatingException) { } catch (Exception ex) { MQThreadExceptionHandler?.Invoke(ex); } } } catch (Exception ex) { MQThreadExceptionHandler?.Invoke(ex); } }