.NET Controls: The Timer


The Timer



A timer is a non-spatial object that uses recurring lapses of time in a computer or in your application. To work, every lapse of period, the control sends a message to the operating system. The message is something to the effect of "I have counted the number of lapses you asked me to count".

As opposed to the time that controls your computer, a timer is partly but greatly under your control. Users do not see nor do they use a timer as a control. As a programmer, you decide if, why, when, and how to use this control.

To support timers, the .NET Framework provides the Timer control from the Toolbox and it is implemented through the Timer class. To add it to your application at design time, on the Toolbox, click Timer and click the form. 

Characteristics of a Timer

A timer is an object used to count lapses of time and send a message when it has finished counting. Each count is called a tick. When a tick occurs, the control fires a Tick event. This Tick event is of type EventArgs, meaning that it doesn't provide more information than to let you know that a lapse has occurred.

The amount of time allocated for counting is called an interval and it is represented by the Interval property. The Interval is a very important characteristic of the Timer control because it measures and controls the total time needed to perform a complete count. The Interval is measured in milliseconds. Like any counter, the lower the value, the faster the count will finish, and the higher the value, the longer the count (if you ask one kid to count from 1 to 10 and you ask another to count from 1 to 20 at the same time, if you ask them to shout when they finish, the first kid would finish first and would shout first). The amount of interval you specify will depend on what you are trying to do.

In order for a timer to count, you must tell it when it should start counting. In some applications, you may want the control to work full-time while in some other applications, you may want the control to work only in response to an intermediate event. The ability to stop and start a Timer control can be set using the Enabled Boolean property. When, or as soon as, this property is set to true, the control starts counting. You can also make it start by calling the Timer.Start() method. Its syntax is:

public void Start();

If, when, or as soon as, the Enabled property is set to false, the control stops and resets its counter to 0. You can also stop the timer by calling the Timer.Stop() method. Its syntax is:

public void Stop();


Tick Counter

Progressive Clock


Home Copyright © 2004-2010 FunctionX, Inc.