public EventTimerEvent AddTime(int milliseconds, Action then, int interval = 0) { DateTime time = DateTime.Now.AddMilliseconds(milliseconds); var e = new EventTimerEvent(then, interval); _queue.Add(new KeyValuePair<DateTime, EventTimerEvent>(time, e)); return e; }
public EventTimerEvent AddTime(int milliseconds, Action then, int interval = 0) { DateTime time = DateTime.Now.AddMilliseconds(milliseconds); var e = new EventTimerEvent(then, interval); _queue.Add(new KeyValuePair <DateTime, EventTimerEvent>(time, e)); return(e); }
public void Run(DateTime now) { for (KeyValuePair <DateTime, EventTimerEvent> i = _queue.FirstOrDefault(); _queue.Count != 0 && i.Key <= now; i = _queue.FirstOrDefault()) { EventTimerEvent value = i.Value; value.Execute(); _queue.Remove(i); if (value.Interval != 0) { _queue.Add(new KeyValuePair <DateTime, EventTimerEvent>(i.Key.AddMilliseconds(value.Interval), value)); } } }