Class Timer
Provides a mechanism for executing a method on a thread pool thread at specified intervals. This class cannot be inherited.
public sealed class Timer : MarshalByRefObject, IDisposable
- Inheritance
-
Timer
- Implements
- Inherited Members
- Extension Methods
Constructors
Timer(TimerCallback, object, int, int)
Initializes a new instance of the Timer class, using a 32-bit signed integer to specify the time interval.
public Timer(TimerCallback callback, object state, int dueTime, int period)
Parameters
callback
TimerCallbackA TimerCallback delegate representing a method to be executed.
state
objectAn object containing information to be used by the callback method, or null.
dueTime
intThe amount of time to delay before callback is invoked, in milliseconds. Specify Timeout.Infinite to prevent the timer from starting. Specify zero (0) to start the timer immediately.
period
intThe time interval between invocations of callback, in milliseconds. Specify Timeout.Infinite to disable periodic signaling.
Timer(TimerCallback, object, TimeSpan, TimeSpan)
Initializes a new instance of the Timer class, using TimeSpan values to measure time intervals.
public Timer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)
Parameters
callback
TimerCallbackA delegate representing a method to be executed.
state
objectAn object containing information to be used by the callback method, or null.
dueTime
TimeSpanThe amount of time to delay before the callback parameter invokes its methods. Specify negative one (-1) milliseconds to prevent the timer from starting. Specify zero (0) to start the timer immediately.
period
TimeSpanThe time interval between invocations of the methods referenced by callback. Specify negative one (-1) milliseconds to disable periodic signaling.
Methods
Change(int, int)
Changes the start time and the interval between method invocations for a timer, using 32-bit signed integers to measure time intervals.
public bool Change(int dueTime, int period)
Parameters
dueTime
intThe amount of time to delay before the invoking the callback method specified when the Timer was constructed, in milliseconds. Specify Timeout.Infinite to prevent the timer from restarting. Specify zero (0) to restart the timer immediately.
period
intThe time interval between invocations of the callback method specified when the Timer was constructed, in milliseconds. Specify Timeout.Infinite to disable periodic signaling.
Returns
- bool
true if the timer was successfully updated; otherwise, false.
Change(TimeSpan, TimeSpan)
Changes the start time and the interval between method invocations for a timer, using TimeSpan values to measure time intervals.
public bool Change(TimeSpan dueTime, TimeSpan period)
Parameters
dueTime
TimeSpanA TimeSpan representing the amount of time to delay before invoking the callback method specified when the Timer was constructed. Specify negative one (-1) milliseconds to prevent the timer from restarting. Specify zero (0) to restart the timer immediately.
period
TimeSpanThe time interval between invocations of the callback method specified when the Timer was constructed. Specify negative one (-1) milliseconds to disable periodic signaling.
Returns
- bool
true if the timer was successfully updated; otherwise, false.
Dispose()
Releases all resources used by the current instance of Timer.
public void Dispose()