Example #1
0
        public void Run()
        {
            bool bWait = false;

            while (_bKeepRunning)
            {
                if (_mds == null || _mds.IsConectado() == false)
                {
                    _mds = new MDSPackageSocket();

                    _mds.IpAddr = _config.MDSAddress;
                    _mds.Port   = _config.MDSPort;

                    _mds.OnFastQuoteReceived += new MDSMessageReceivedHandler(OnCotacao);
                    _mds.OpenConnection();
                }

                List <CotacaoANG> tmpQueue = new List <CotacaoANG>();

                lock (queueCotacao)
                {
                    tmpQueue = queueCotacao.ToList();
                    queueCotacao.Clear();
                }

                foreach (CotacaoANG cotacao in tmpQueue)
                {
                    GravarNegocio(cotacao);
                }

                lock (queueCotacao)
                {
                    if (queueCotacao.Count == 0)
                    {
                        bWait = true;
                    }
                    else
                    {
                        bWait = false;
                    }
                }

                if (bWait)
                {
                    Thread.Sleep(250);
                }
            }
        }
Example #2
0
        public void Run()
        {
            bool bWait   = false;
            long lastlog = 0;

            while (_bKeepRunning)
            {
                if (_mds == null || _mds.IsConectado() == false)
                {
                    _mds = new MDSPackageSocket();

                    _mds.IpAddr = _config.MDSAddress;
                    _mds.Port   = _config.MDSPort;

                    _mds.OnFastQuoteReceived += new MDSMessageReceivedHandler(OnCotacao);
                    _mds.OpenConnection();
                }

                CotacaoANG cotacao = null;
                if (queueCotacao.TryDequeue(out cotacao))
                {
                    GravarNegocio(cotacao);

                    TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - lastlog);
                    if (ts.TotalMilliseconds > 2000)
                    {
                        logger.Info("Mensagens de cotacao para gravar no banco: " + queueCotacao.Count);
                        lastlog = DateTime.Now.Ticks;
                    }

                    continue;
                }

                Thread.Sleep(100);
            }
        }