/// <summary> /// 外部设置延迟多少秒时间的任务 方法由外部指定 /// </summary> /// <param name="id"></param> /// <param name="delaytime"></param> public void AddTimerEvent(long delaytime, TimerDG td) { long time = DateTime.Now.Ticks + delaytime; TimerModle timerModle = new TimerModle(concurrentID.Add_Get(), time, td); idTimerDic.TryAdd(timerModle.ID, timerModle); }
/// <summary> /// 设置定时触发的任务 /// </summary> /// <param name="dateTime"></param> /// <param name="td"></param> public void AddTimerEvent(DateTime dateTime, TimerDG td) { long delaytime = dateTime.Ticks - DateTime.Now.Ticks; if (delaytime < 0) { return; //如果延迟时间小于0 证明定时日期在过去 } TimerModle timerModle = new TimerModle(concurrentID.Add_Get(), delaytime, td); idTimerDic.TryAdd(timerModle.ID, timerModle); }
public TimerModle(int id, long time, TimerDG td) { ID = id; Time = time; TimerEvent += td; }