Esempio n. 1
0
            public void 添加事项 <T>(string __队列标识, T __数据, Action <T> __处理数据, H队列监控 __监控 = null)
            {
                if (_已关闭)
                {
                    return;
                }
                //Debug.WriteLine("{0} 添加事项 {1}", DateTime.Now.ToString("HH:mm:ss.fff"), __数据);
                var __接收时间 = Environment.TickCount;
                var __队列   = _队列字典.GetOrAdd(__队列标识, k => new ConcurrentQueue <Action>());

                __队列.Enqueue(() =>
                {
                    if (!_取消标志.IsCancellationRequested)
                    {
                        try
                        {
                            //Debug.WriteLine("{0} 执行事项 {1}", DateTime.Now.ToString("HH:mm:ss.fff"), __数据);
                            if (__监控 == null)
                            {
                                __处理数据(__数据);
                            }
                            else
                            {
                                __监控.监控下执行(_名称, __数据, __接收时间, __处理数据);
                            }
                        }
                        catch (Exception ex)
                        {
                            H日志输出.记录(ex, _名称);
                        }
                    }
                });
                Interlocked.Increment(ref _待处理数量);
            }
Esempio n. 2
0
            public void 添加事项 <T>(T __数据, Action <T> __处理数据, H队列监控 __监控 = null)
            {
                //Debug.WriteLine("{0} 添加事项 {1}", DateTime.Now.ToString("HH:mm:ss.fff"), __数据);
                if (_已关闭)
                {
                    return;
                }
                var    __接收时间 = Environment.TickCount;
                Action __任务项  = () =>
                {
                    try
                    {
                        //Debug.WriteLine("{0} 执行事项 {1}", DateTime.Now.ToString("HH:mm:ss.fff"), __数据);
                        if (__监控 == null)
                        {
                            __处理数据(__数据);
                        }
                        else
                        {
                            __监控.监控下执行(_名称, __数据, __接收时间, __处理数据);
                        }
                    }
                    catch (Exception ex)
                    {
                        H日志输出.记录(ex, _名称);
                    }
                };

                _队列.Enqueue(__任务项);
                if (_队列.Count == 1)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Action __事项;
                        while (_队列.TryDequeue(out __事项))
                        {
                            if (_取消标志.IsCancellationRequested)
                            {
                                break;
                            }
                            __事项();
                        }
                        if (_已关闭)
                        {
                            _同步信号.Set();
                            return;
                        }
                    }, _取消标志.Token);
                }
            }
Esempio n. 3
0
 /// <param name="__延迟阈值">毫秒</param>
 /// <param name="__耗时阈值">毫秒</param>
 public H线程队列(int __分组统计数量 = 1000, int __延迟阈值 = 3000, int __耗时阈值 = 100)
 {
     _监控 = new H队列监控(__分组统计数量, __延迟阈值, __耗时阈值);
 }