Пример #1
0
        public void Update()
        {
            if (!_isMultiThreaded)
            {
                foreach (var channel in _channels.ForRead())
                {
                    channel.ProcessSerializeQueue();
                    channel.ProcessDeserializeQueue();
                }
            }

            if (!_isMultiThreaded || _sendRecvInMain)
            {
                ProcessSendReceive(false);
            }
        }
Пример #2
0
        protected override void Run()
        {
            Thread.CurrentThread.Name = GetType().ToString();
            while (Running)
            {
                try
                {
                    var copy = _holder.ForRead().FindAll(x => x.Id % _threadCount == _threadIdx);


                    _stopwatch.Reset();
                    _stopwatch.Start();
                    bool hasWork = false;
                    if (!IsSuspend)
                    {
                        hasWork = DoProcesssAll();
                        foreach (var channel in copy)
                        {
                            hasWork = DoProcessChannel(channel) || hasWork;
                        }
                    }

                    _stopwatch.Stop();
                    var span  = _stopwatch.ElapsedTicks / 10000f;
                    var sleep = (int)(_pollIntval - span);
                    _runningTime += span;
                    _stopwatch.Start();
                    if (!hasWork && sleep >= 0 && sleep < _pollIntval)
                    {
                        Thread.Sleep(sleep);
                    }

                    _stopwatch.Stop();
                    _totalTime += _stopwatch.ElapsedTicks / 10000f;
                    if (_totalTime >= 5000)
                    {
                        _rate        = (float)(100 * _runningTime / (_totalTime));
                        _totalTime   = 0;
                        _runningTime = 0;
                    }
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("Thread {0} error {1}", Name, e);
                }
            }
        }