public void Start(ITimerItem item) { Timer key = new Timer(); key.AutoReset = false; key.Interval = item.Interval; key.SynchronizingObject = item.SynchronizingObject; key.Elapsed += new ElapsedEventHandler(this.OnElapsed); lock (this.items) this.items.Add(key, item); key.Start(); }
public void Stop(ITimerItem item) { lock (this.items) { foreach (KeyValuePair<Timer, ITimerItem> item_0 in this.items) { if (item_0.Value == item) { this.items.Remove(item_0.Key); break; } } } }
public void Stop(ITimerItem item) { lock (this.items) { foreach (KeyValuePair <Timer, ITimerItem> item_0 in this.items) { if (item_0.Value == item) { this.items.Remove(item_0.Key); break; } } } }
protected static void Add(ITimerItem titem) { //按时间倒序 bool isInsert = false; for (int i = 0; i < m_timerItemList.Count; i++) { if (titem.NextTime <= m_timerItemList[i].NextTime) { m_timerItemList.Insert(i, titem); isInsert = true; break; } } if (!isInsert) { m_timerItemList.Add(titem); } }
/// <summary> /// Returns true if last of event of timer is cancelled event. /// </summary> /// <param name="timerItem"></param> /// <returns></returns> public static bool IsCancelled(this ITimerItem timerItem) => timerItem.LastEvent() is TimerCancelledEvent;
/// <summary> /// Returns true if last event of timer is fired event. /// </summary> /// <param name="timerItem"></param> /// <returns></returns> public static bool IsFired(this ITimerItem timerItem) => timerItem.LastEvent() is TimerFiredEvent;