Exemplo n.º 1
0
            public void Open()
            {
                _messageQueue.Open();

                ThreadingHelper
                .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() =>
                {
                    while (!_messageQueue.IsClosed)
                    {
                        try
                        {
                            var sended    = _historyMessageAdapter.SendOutMessage();
                            var processed = false;

                            while (_messageQueue.TryDequeue(out var message, true, false))
                            {
                                NewOutMessage?.Invoke(message);
                                processed = true;
                            }

                            if (!sended && !processed && !_messageQueue.IsClosed)
                            {
                                Thread.Sleep(100);
                            }
                        }
                        catch (Exception ex)
                        {
                            _errorHandler(ex);
                        }
                    }
                }))
                .Name("History emulation channel thread.")
                .Launch();
            }
Exemplo n.º 2
0
            public void Open()
            {
                _messageQueue.Open();

                ThreadingHelper
                .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() =>
                {
                    while (!_messageQueue.IsClosed)
                    {
                        try
                        {
                            var sended = _historyMessageAdapter.SendOutMessage();

                            Message message;

                            if (!_messageQueue.TryDequeue(out message, true, !sended))
                            {
                                if (!sended)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                NewOutMessage?.Invoke(message);
                            }
                        }
                        catch (Exception ex)
                        {
                            _errorHandler(ex);
                        }
                    }
                }))
                .Name("History emulation channel thread.")
                .Launch();
            }