Timer Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Provides a mechanism for executing a method at specified intervals. This class cannot be inherited.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

[<Sealed>]
type Timer =  
    class
        inherit MarshalByRefObject
        interface IDisposable
    end

The Timer type exposes the following members.

  NameDescription
Public methodTimer(TimerCallback, Object, Int32, Int32)Initializes a new instance of the Timer class, using a 32-bit signed integer to specify the time interval.
Public methodTimer(TimerCallback, Object, TimeSpan, TimeSpan)Initializes a new instance of the Timer class, using TimeSpan values to measure time intervals.
Top

  NameDescription
Public methodChange(Int32, Int32)Changes the start time and the interval between method invocations for a timer, using 32-bit signed integers to measure time intervals.
Public methodChange(TimeSpan, TimeSpan)Changes the start time and the interval between method invocations for a timer, using TimeSpan values to measure time intervals.
Public methodDisposeReleases all resources used by the current instance of Timer.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Use a TimerCallback delegate to specify the method you want the Timer to execute. The timer delegate is specified when the timer is constructed, and cannot be changed. The method does not execute on the thread that created the timer; it executes on a ThreadPool thread supplied by the system.

When you create a timer, you can specify an amount of time to wait before the first execution of the method (due time), and an amount of time to wait between subsequent executions (period). You can change these values, or disable the timer, using the Change method.

When a timer is no longer needed, use the Dispose method to free the resources held by the timer. Note that callbacks can occur after the Dispose()()()() method overload has been called, because the timer queues callbacks for execution by thread pool threads. You can use the Dispose(WaitHandle) method overload to wait until all callbacks have completed.

The callback method executed by the timer should be reentrant, because it is called on ThreadPool threads. The callback can be executed simultaneously on two thread pool threads if the timer interval is less than the time required to execute the callback, or if all thread pool threads are in use and the callback is queued multiple times.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: