コード例 #1
0
 public InternalCallbackTimer(/*CallbackBlockPool pool,*/ TaskFactory factory)
 {
     _factory = factory;
     //_pool = pool;
     _timer = new TimerEx(onTmer, 450, null);
     _timer.IsStopWhenRun = true;
     _timer.Start();
 }
コード例 #2
0
ファイル: GlobalCache.cs プロジェクト: jiazhebaba/Kugar.Core
        public GlobalCache()
        {
            _cacheData = new ConcurrentDictionary <string, ICacheItem>();

            _timer = new TimerEx(Timer_Callback, 300, null);

            _timer.IsStopWhenRun = true;

            _timer.Start();

            //System.Data.SqlClient.SqlDependency
        }
コード例 #3
0
        public TimerPool_Item Add(int timerInterval, TimerPoolItemCallback callback, object state = null, bool isStart = true)
        {
            var item = new TimerPool_Item(this, callback, state, timerInterval);

            lock (lockerObj)
            {
                var index = -1;

                //查找第一个小于10000个托管定时任务的定时列表
                if (_delgateList.Count > 0)
                {
                    for (int i = 0; i < _delgateList.Count; i++)
                    {
                        if (_delgateList[i].Count < 10000)
                        {
                            index = i;
                            break;
                        }
                    }
                }


                //如果都大于或等于10000的话,则添加一个新的
                if (index == -1)
                {
                    var newList = new List <TimerPool_Item>(1000);

                    _delgateList.Add(newList);

                    index = _delgateList.Count - 1;

                    var newtimer = new TimerEx(CheckerList, 2000, newList);

                    _checkTimer.Add(newtimer);

                    if (isStart)
                    {
                        newtimer.Start();
                    }
                }

                _delgateList[index].Add(item);

                if (_delgateList.Count > 3)
                {
                    _delgateList.Sort((x, y) => x.Count.CompareTo(y.Count));
                }
            }

            return(item);
        }
コード例 #4
0
        public TimerPool(int timerCount)
        {
            //delgateList = new List<TimerPool_Item>(50);
            //_checkTimer = new TimerEx(CheckerList, 200, null);

            _delgateList = new List <List <TimerPool_Item> >(timerCount);
            _checkTimer  = new List <TimerEx>(timerCount);


            var newList  = new List <TimerPool_Item>(1000);
            var newtimer = new TimerEx(CheckerList, 200, newList);

            _delgateList.Add(newList);
            _checkTimer.Add(newtimer);

            newtimer.Start();
        }
コード例 #5
0
        public AutoResetEventPool(int initPoolCount)
        {
            if (initPoolCount < 0)
            {
                throw new ArgumentOutOfRangeException("initPoolCount");
            }

            cacheItemPool = new Dictionary <int, AutoResetEventItem>();
            freeItemList  = new Stack <AutoResetEventItem>();

            for (int i = 0; i < initPoolCount; i++)
            {
                var tempItem = new AutoResetEventItem();
                tempItem.LastUsedTime = DateTime.Now;

                freeItemList.Push(tempItem);
            }

            timer = new TimerEx(OnTimerCallback, 60000, null);

            timer.Start();
        }