Пример #1
0
        public bool RemoveTimer(int timerId)
        {
            LTTimerData timer = null;

            if (_timerMap.TryGetValue(timerId, out timer))
            {
                _timerMap.Remove(timerId);
                _timerList.Remove(timer);
                _dataPool.Return(timer);
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// 生成一个唯一TimerID
        /// </summary>
        /// <returns></returns>
        private int _GenTimerID(LTTimerData data)
        {
            int genID = _genId;

            while (true)
            {
                if (!_timerMap.ContainsKey(genID))
                {
                    _timerMap[genID] = data;
                    data.id          = genID;
                    break;
                }
                genID = ++_genId;
                if (_genId == int.MaxValue)
                {
                    _genId = int.MinValue;
                }
            }
            return(genID);
        }