コード例 #1
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();
        }
コード例 #2
0
        public AutoResetEventItem GetLockItem()
        {
            AutoResetEventItem autoItem = null;

            try
            {
                lock (lockerObj)
                {
                    autoItem = freeItemList.Pop();

                    //cacheItemPool.Add(autoItem.ID, autoItem);
                }
            }
            catch (Exception)
            {
                autoItem            = new AutoResetEventItem();
                autoItem.LockStart += autoItem_LockStart;
                autoItem.UnLock    += autoItem_UnLock;
            }

            autoItem.LastUsedTime = DateTime.Now;

            return(autoItem);
        }