public Timer(float interval, OnTimerHandler handler) { TimeEvent += handler; Interval = interval; _scale = 1; ElapsedTime = 0; SeqId = TimerSeq.Get(); }
// 添加时间事件 public bool AddHandler(OnTimerHandler handler) { //1. 异常情况,handler已经被加入 if (TimeEvent != null && HandlerExist(handler, TimeEvent)) { return(false); } //2.正常情况,加入handler TimeEvent += handler; return(true); }
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); }
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 (); } }
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; } }
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(); } }
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)); }
//count 如果小于等于0,相当于无限次 public TimerMulti(float interval, int repeatCount, OnTimerHandler handler) : base(interval, handler) { _repeatCount = repeatCount; _count = 0; }
public static Timer AddTimer(float interval, OnTimerHandler handler) { return(AddTimer(interval, 1, handler)); }