Class TimerEx
A facility for applications to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals. Unlike the normal .NET Timer this Timer allows for multiple tasks to be scheduled in a single Timer object.
Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially. Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.
After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer's task execution thread terminates gracefully (and becomes subject to garbage collection). However, this can take arbitrarily long to occur. By default, the task execution thread does not run as a Background thread, so it is capable of keeping an application from terminating. If a caller wants to terminate a timer's task execution thread rapidly, the caller should invoke the timer's cancel method.
If the timer's task execution thread terminates unexpectedly, any further attempt to schedule a task on the timer will result in an IllegalStateException, as if the timer's cancel method had been invoked.
This class is thread-safe: multiple threads can share a single Timer object without the need for external synchronization.
This class does not offer real-time guarantees: it schedules tasks using the EventWaitHandle.WaitOne(TimeSpan) method.
Inheritance
Inherited Members
Namespace: Apache.NMS.ActiveMQ.Threads
Assembly: Apache.NMS.ActiveMQ.dll
Syntax
public class TimerEx
Constructors
| Improve this Doc View SourceTimerEx()
Declaration
public TimerEx()
TimerEx(Boolean)
Declaration
public TimerEx(bool isBackground)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | isBackground |
TimerEx(String)
Declaration
public TimerEx(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
TimerEx(String, Boolean)
Declaration
public TimerEx(string name, bool isBackground)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | |
System.Boolean | isBackground |
Methods
| Improve this Doc View SourceCancel()
Terminates this timer, discarding any currently scheduled tasks. Does not interfere with a currently executing task (if it exists). Once a timer has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.
Note that calling this method from within the run method of a timer task that was invoked by this timer absolutely guarantees that the ongoing task execution is the last task execution that will ever be performed by this timer.
This method may be called repeatedly; the second and subsequent calls have no effect.
Declaration
public void Cancel()
Purge()
Removes all cancelled tasks from this timer's task queue. Calling this method has no effect on the behavior of the timer, but eliminates the references to the cancelled tasks from the queue. If there are no external references to these tasks, they become eligible for garbage collection.
Most programs will have no need to call this method. It is designed for use by the rare application that cancels a large number of tasks. Calling this method trades time for space: the runtime of the method may be proportional to n + c log n, where n is the number of tasks in the queue and c is the number of cancelled tasks.
Note that it is permissible to call this method from within a a task scheduled on this timer.
Declaration
public int Purge()
Returns
Type | Description |
---|---|
System.Int32 |
Schedule(TimerTask, DateTime)
Schedules the specified TimerTask for execution at the specified time. If the time is in the past.
Declaration
public void Schedule(TimerTask task, DateTime when)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.DateTime | when |
Schedule(TimerTask, DateTime, Int32)
Schedules the specified TimerTask for repeated fixed-delay execution, beginning at the specified 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.
Declaration
public void Schedule(TimerTask task, DateTime when, int period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.DateTime | when | |
System.Int32 | period |
Schedule(TimerTask, DateTime, TimeSpan)
Schedules the specified TimerTask for repeated fixed-delay execution, beginning at the specified 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.
Declaration
public void Schedule(TimerTask task, DateTime when, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.DateTime | when | |
System.TimeSpan | period |
Schedule(TimerTask, Int32)
Schedules the specified TimerTask for execution after the specified delay.
Declaration
public void Schedule(TimerTask task, int delay)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.Int32 | delay |
Schedule(TimerTask, Int32, Int32)
Schedules the specified TimerTask for repeated fixed-delay execution, beginning after the specified delay. 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.
Declaration
public void Schedule(TimerTask task, int delay, int period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.Int32 | delay | |
System.Int32 | period |
Schedule(TimerTask, TimeSpan)
Schedules the specified TimerTask for execution after the specified delay.
Declaration
public void Schedule(TimerTask task, TimeSpan delay)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.TimeSpan | delay |
Schedule(TimerTask, TimeSpan, TimeSpan)
Schedules the specified TimerTask for repeated fixed-delay execution, beginning after the specified delay. 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.
Declaration
public void Schedule(TimerTask task, TimeSpan delay, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.TimeSpan | delay | |
System.TimeSpan | period |
Schedule(WaitCallback, Object, DateTime)
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.
Declaration
public TimerTask Schedule(WaitCallback callback, object arg, DateTime when)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.DateTime | when |
Returns
Type | Description |
---|---|
TimerTask |
Schedule(WaitCallback, Object, DateTime, Int32)
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.
Declaration
public TimerTask Schedule(WaitCallback callback, object arg, DateTime when, int period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.DateTime | when | |
System.Int32 | period |
Returns
Type | Description |
---|---|
TimerTask |
Schedule(WaitCallback, Object, DateTime, TimeSpan)
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.
Declaration
public TimerTask Schedule(WaitCallback callback, object arg, DateTime when, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.DateTime | when | |
System.TimeSpan | period |
Returns
Type | Description |
---|---|
TimerTask |
Schedule(WaitCallback, Object, Int32)
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.
Declaration
public TimerTask Schedule(WaitCallback callback, object arg, int delay)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.Int32 | delay |
Returns
Type | Description |
---|---|
TimerTask |
Schedule(WaitCallback, Object, Int32, Int32)
Schedules the specified WaitCallback task for repeated fixed-delay execution, beginning after the specified delay. 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.
Declaration
public TimerTask Schedule(WaitCallback callback, object arg, int delay, int period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.Int32 | delay | |
System.Int32 | period |
Returns
Type | Description |
---|---|
TimerTask |
Schedule(WaitCallback, Object, TimeSpan)
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.
Declaration
public TimerTask Schedule(WaitCallback callback, object arg, TimeSpan delay)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.TimeSpan | delay |
Returns
Type | Description |
---|---|
TimerTask |
Schedule(WaitCallback, Object, TimeSpan, TimeSpan)
Schedules the specified WaitCallback task for repeated fixed-delay execution, beginning after the specified delay. 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.
Declaration
public TimerTask Schedule(WaitCallback callback, object arg, TimeSpan delay, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.TimeSpan | delay | |
System.TimeSpan | period |
Returns
Type | Description |
---|---|
TimerTask |
ScheduleAtFixedRate(TimerTask, DateTime, Int32)
Schedules the specified TimerTask for repeated fixed-rate execution, beginning at the specified time. 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.
Declaration
public void ScheduleAtFixedRate(TimerTask task, DateTime when, int period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.DateTime | when | |
System.Int32 | period |
ScheduleAtFixedRate(TimerTask, DateTime, TimeSpan)
Schedules the specified TimerTask for repeated fixed-rate execution, beginning at the specified time. 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.
Declaration
public void ScheduleAtFixedRate(TimerTask task, DateTime when, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.DateTime | when | |
System.TimeSpan | period |
ScheduleAtFixedRate(TimerTask, Int32, Int32)
Schedules the specified TimerTask 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.
Declaration
public void ScheduleAtFixedRate(TimerTask task, int delay, int period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.Int32 | delay | |
System.Int32 | period |
ScheduleAtFixedRate(TimerTask, TimeSpan, TimeSpan)
Schedules the specified TimerTask 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.
Declaration
public void ScheduleAtFixedRate(TimerTask task, TimeSpan delay, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
TimerTask | task | |
System.TimeSpan | delay | |
System.TimeSpan | period |
ScheduleAtFixedRate(WaitCallback, Object, DateTime, Int32)
Schedules the specified WaitCallback task for repeated fixed-rate execution, beginning at the specified time. 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.
Declaration
public TimerTask ScheduleAtFixedRate(WaitCallback callback, object arg, DateTime when, int period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.DateTime | when | |
System.Int32 | period |
Returns
Type | Description |
---|---|
TimerTask |
ScheduleAtFixedRate(WaitCallback, Object, DateTime, TimeSpan)
Schedules the specified WaitCallback task for repeated fixed-rate execution, beginning at the specified time. 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.
Declaration
public TimerTask ScheduleAtFixedRate(WaitCallback callback, object arg, DateTime when, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.DateTime | when | |
System.TimeSpan | period |
Returns
Type | Description |
---|---|
TimerTask |
ScheduleAtFixedRate(WaitCallback, Object, Int32, Int32)
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.
Declaration
public TimerTask ScheduleAtFixedRate(WaitCallback callback, object arg, int delay, int period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.Int32 | delay | |
System.Int32 | period |
Returns
Type | Description |
---|---|
TimerTask |
ScheduleAtFixedRate(WaitCallback, Object, TimeSpan, TimeSpan)
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.
Declaration
public TimerTask ScheduleAtFixedRate(WaitCallback callback, object arg, TimeSpan delay, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.WaitCallback | callback | |
System.Object | arg | |
System.TimeSpan | delay | |
System.TimeSpan | period |
Returns
Type | Description |
---|---|
TimerTask |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |