private void AddTimeEvent(TimeOutProcess process, object processParam, DateTime startTime, DateTime endTime, double interval, int excuteTimes) { if (!timeOutBlocks.ContainsKey(startTime)) { timeOutBlocks.Add(startTime, new List <TimeOutBlock>()); } var blocks = timeOutBlocks[startTime]; lock (syncObj) { blocks.Add(new TimeOutBlock(process, processParam, startTime, endTime, interval, excuteTimes)); if (startTime < nextCheckTime) { nextCheckTime = startTime; } } }
/// <summary> /// /// </summary> /// <param name="process"></param> /// <param name="processParam"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="interval">Milliseconds</param> /// <param name="excuteTimes"></param> public TimeOutBlock(TimeOutProcess process, object processParam, DateTime startTime, DateTime endTime, double interval, int excuteTimes) { this.process = process; this.param = processParam; this.Interval = interval; this.excuteTimes = excuteTimes; this.currentExcuteTime = 0; this.endTime = endTime; if (startTime > DateTime.Now) { this.nextTimeOutTime = startTime; } else { this.nextTimeOutTime = DateTime.Now.AddMilliseconds(interval); } }
/// <summary> /// Add time arrive event with end time. /// </summary> /// <param name="process">Process to do when time arrive.</param> /// <param name="processParam">Parameter to pass to the Process.</param> /// <param name="startTime">First arrive time.</param> /// <param name="endTime">The end time of time arrive event</param> /// <param name="interval">Interval(Milliseconds) to reach another time arrive event.</param> public void AddTimeEvent(TimeOutProcess process, object processParam, DateTime startTime, DateTime endTime, double interval) { AddTimeEvent(process, processParam, startTime, endTime, interval, -1); }
/// <summary> /// Add time arrive event with the number of time arrive event repetitions. /// </summary> /// <param name="process">Process to do when time arrive.</param> /// <param name="processParam">Parameter to pass to the Process.</param> /// <param name="startTime">First arrive time.</param> /// <param name="interval">Interval(Milliseconds) to reach another time arrive event.</param> /// <param name="excuteTimes">The number of time arrive event repetitions.</param> public void AddTimeEvent(TimeOutProcess process, object processParam, DateTime startTime, double interval, int excuteTimes) { AddTimeEvent(process, processParam, startTime, DateTime.MaxValue, interval, excuteTimes); }