Пример #1
0
 public Timer(float interval, OnTimerHandler handler)
 {
     TimeEvent  += handler;
     Interval    = interval;
     _scale      = 1;
     ElapsedTime = 0;
     SeqId       = TimerSeq.Get();
 }
Пример #2
0
        // 添加时间事件
        public bool AddHandler(OnTimerHandler handler)
        {
            //1. 异常情况,handler已经被加入
            if (TimeEvent != null && HandlerExist(handler, TimeEvent))
            {
                return(false);
            }

            //2.正常情况,加入handler
            TimeEvent += handler;
            return(true);
        }
Пример #3
0
        public static Timer AddTimer(float interval, int repeatCount, OnTimerHandler handler)
        {
            Timer t = null;

            if (repeatCount == 1)
            {
                t = new Timer(interval, handler);
            }
            else
            {
                t = new TimerMulti(interval, repeatCount, handler);
            }
            TimerManager.Instance.AddTimer(t);
            return(t);
        }
Пример #4
0
        public void RegisterCallback(int MillisecondTimeout, OnTimerHandler CB)
        {
            lock (TheList) {
                DateTime WaitTime;
                if (TheList.Count == 0) {
                    StartTime = DateTime.Now;
                }
                WaitTime = DateTime.Now.AddMilliseconds (MillisecondTimeout);

                if (TheList.ContainsKey (WaitTime.Ticks) == false) {
                    TheList [WaitTime.Ticks] = new ArrayList ();
                }
                ((ArrayList)TheList [WaitTime.Ticks]).Add (CB);
                TimerThread.Interrupt ();
            }
        }
Пример #5
0
 public Timer(OnTimerHandler handler, object[] args, bool isCycled, float startTime, float delay, float endTime)
 {
     _action    = handler;
     _args      = args;
     _isCycled  = isCycled;
     _startTime = startTime;
     _endTime   = endTime;
     if (!isCycled)
     {
         delay     = _endTime;
         _nextTime = _endTime;
     }
     else
     {
         _delay    = delay;
         _nextTime = _startTime;
     }
 }
Пример #6
0
        public void RegisterCallback(int MillisecondTimeout, OnTimerHandler CB)
        {
            lock (TheList) {
                DateTime WaitTime;
                if (TheList.Count == 0)
                {
                    StartTime = DateTime.Now;
                }
                WaitTime = DateTime.Now.AddMilliseconds(MillisecondTimeout);

                if (TheList.ContainsKey(WaitTime.Ticks) == false)
                {
                    TheList [WaitTime.Ticks] = new ArrayList();
                }
                ((ArrayList)TheList [WaitTime.Ticks]).Add(CB);
                TimerThread.Interrupt();
            }
        }
Пример #7
0
 public static void AddTimer(OnTimerHandler handler, object[] args, bool isCycled, float startTime, float delay, float endTime)
 {
     _timers.Add(new Timer(handler, args, isCycled, startTime, delay, endTime));
 }
Пример #8
0
 //count 如果小于等于0,相当于无限次
 public TimerMulti(float interval, int repeatCount, OnTimerHandler handler)
     : base(interval, handler)
 {
     _repeatCount = repeatCount;
     _count       = 0;
 }
Пример #9
0
 public static Timer AddTimer(float interval, OnTimerHandler handler)
 {
     return(AddTimer(interval, 1, handler));
 }