Ejemplo n.º 1
0
        public static Timer Add(long interval, int repeatTimes, object[] args, DelegateOnTimer onTimer, DelegateOnTimer onRemoved)
        {
            if (onTimer == null)
                return null;

            Timer timer = new Timer();
            timer.interval_ = interval * 10000;
            timer.repeatTimes_ = repeatTimes;
            timer.args_ = args;
            timer.triggerTime_ = watch_.Elapsed.Ticks + timer.interval_;
            timer.onTimer_ = onTimer;
            timer.onRemoved_ = onRemoved;
            timerList_.AddLast(timer);

            return timer;
        }
Ejemplo n.º 2
0
        public static void Remove(Timer timer)
        {
            LinkedListNode<Timer> curNode = timerList_.First;
            while (curNode != null)
            {
                LinkedListNode<Timer> next = curNode.Next;

                if (curNode.Value != timer)
                {
                    curNode = next;
                    continue;
                }

                timerList_.Remove(curNode);
                if (timer.onRemoved_ != null)
                {
                    timer.onRemoved_(timer);
                }
                break;
            }
        }