/// <summary> /// Schedules the specified WaitCallback task for execution at the specified time. If the /// time is in the past, the task is scheduled for immediate execution. The method returns /// a TimerTask instance that can be used to later cancel the scheduled task. /// </summary> public TimerTask Schedule(WaitCallback callback, object arg, DateTime when) { InternalTimerTask task = new InternalTimerTask(callback, arg); TimeSpan delay = when - DateTime.Now; DoScheduleImpl(task, delay, TimeSpan.FromMilliseconds(-1), false); return(task); }
/// <summary> /// Schedules the specified WaitCallback task for repeated fixed-rate execution, beginning /// after the specified delay. Subsequent executions take place at approximately regular /// intervals, separated by the specified period. /// /// In fixed-rate execution, each execution is scheduled relative to the scheduled execution /// time of the initial execution. If an execution is delayed for any reason (such as garbage /// collection or other background activity), two or more executions will occur in rapid /// succession to "catch up." /// /// Fixed-rate execution is appropriate for recurring activities that are sensitive to /// absolute time, such as ringing a chime every hour on the hour, or running scheduled /// maintenance every day at a particular time. /// /// The method returns a TimerTask instance that can be used to later cancel the /// scheduled task. /// </summary> public TimerTask ScheduleAtFixedRate(WaitCallback callback, object arg, TimeSpan delay, TimeSpan period) { if (delay.CompareTo(TimeSpan.Zero) < 0 || period.CompareTo(TimeSpan.Zero) <= 0) { throw new ArgumentOutOfRangeException(); } InternalTimerTask task = new InternalTimerTask(callback, arg); DoScheduleImpl(task, delay, period, true); return(task); }
/// <summary> /// Schedules the specified WaitCallback task for repeated fixed-rate execution, beginning /// after the specified delay. Subsequent executions take place at approximately regular /// intervals, separated by the specified period. /// /// In fixed-rate execution, each execution is scheduled relative to the scheduled execution /// time of the initial execution. If an execution is delayed for any reason (such as garbage /// collection or other background activity), two or more executions will occur in rapid /// succession to "catch up." /// /// Fixed-rate execution is appropriate for recurring activities that are sensitive to /// absolute time, such as ringing a chime every hour on the hour, or running scheduled /// maintenance every day at a particular time. /// /// The method returns a TimerTask instance that can be used to later cancel the /// scheduled task. /// </summary> public TimerTask ScheduleAtFixedRate(WaitCallback callback, object arg, int delay, int period) { if (delay < 0 || period <= 0) { throw new ArgumentOutOfRangeException(); } InternalTimerTask task = new InternalTimerTask(callback, arg); DoScheduleImpl(task, TimeSpan.FromMilliseconds(delay), TimeSpan.FromMilliseconds(period), true); return(task); }
/// <summary> /// Schedules the specified WaitCallback task for execution after the specified delay. /// The method returns a TimerTask instance that can be used to later cancel the /// scheduled task. /// </summary> public TimerTask Schedule(WaitCallback callback, object arg, TimeSpan delay) { if (delay.CompareTo(TimeSpan.Zero) < 0) { throw new ArgumentOutOfRangeException(); } InternalTimerTask task = new InternalTimerTask(callback, arg); DoScheduleImpl(task, delay, TimeSpan.FromMilliseconds(-1), false); return(task); }
/// <summary> /// Schedules the specified WaitCallback task for repeated fixed-delay execution, /// beginning at the specified start time. Subsequent executions take place at approximately /// regular intervals separated by the specified period. /// /// In fixed-delay execution, each execution is scheduled relative to the actual execution /// time of the previous execution. If an execution is delayed for any reason (such as /// garbage collection or other background activity), subsequent executions will be delayed. /// /// Fixed-delay execution is appropriate for recurring activities that require "smoothness." /// In other words, it is appropriate for activities where it is more important to keep the /// frequency accurate in the short run than in the long run. /// /// The method returns a TimerTask instance that can be used to later cancel the /// scheduled task. /// </summary> public TimerTask Schedule(WaitCallback callback, object arg, DateTime when, TimeSpan period) { if (period.CompareTo(TimeSpan.Zero) <= 0) { throw new ArgumentOutOfRangeException(); } InternalTimerTask task = new InternalTimerTask(callback, arg); TimeSpan delay = when - DateTime.Now; DoScheduleImpl(task, delay, period, false); return(task); }
/// <summary> /// Schedules the specified WaitCallback task for repeated fixed-delay execution, /// beginning at the specified start time. Subsequent executions take place at approximately /// regular intervals separated by the specified period. /// /// In fixed-delay execution, each execution is scheduled relative to the actual execution /// time of the previous execution. If an execution is delayed for any reason (such as /// garbage collection or other background activity), subsequent executions will be delayed. /// /// Fixed-delay execution is appropriate for recurring activities that require "smoothness." /// In other words, it is appropriate for activities where it is more important to keep the /// frequency accurate in the short run than in the long run. /// /// The method returns a TimerTask instance that can be used to later cancel the /// scheduled task. /// </summary> public TimerTask Schedule(WaitCallback callback, object arg, DateTime when, int period) { if (period <= 0) { throw new ArgumentOutOfRangeException(); } InternalTimerTask task = new InternalTimerTask(callback, arg); TimeSpan delay = when - DateTime.Now; DoScheduleImpl(task, delay, TimeSpan.FromMilliseconds(period), false); return(task); }