Timer Control - VB.Net
What is Timer Control ?
Timer Control plays an important role in the Client side programming and Server side programming, also used in Windows Services. By using this Timer Control, windows allow you to control when actions take place without the interaction of another thread.
Use of Timer Control
We can use Timer Control in many situations in our development environment. If you want to run some code after a certain interval of time continuously, you can use the Timer control. As well as to start a process at a fixed time schedule, to increase or decrease the speed in an animation graphics with time schedule etc. you can use the Timer Control. The Visual Studio toolbox has a Timer Control that allowing you to drag and drop the timer controls directly onto a Windows Forms designer. At runtime it does not have a visual representation and works as a component in the background.
How to Timer Control ?
With the Timer Control, we can control programs in millisecond, seconds, minutes and even in hours. The Timer Control allows us to set Interval property in milliseconds (1 second is equal to 1000 milliseconds). For example, if we want to set an interval of two minute we set the value at Interval property as 120000, means 120x1000 .
The Timer Control starts its functioning only after its Enabled property is set to True, by default Enabled property is False.
The following program shows a Timer example that display current system time in a Label control. For doing this, we need one Label control and a Timer Control. Here in this program, we can see the Label Control is updated each seconds because we set Timer Interval as 1 second, that is 1000 milliseconds. After drag and drop the Timer Control in the designer form , double click the Timer control and set the DateTime.Now.ToString to Label control text property.
Start and Stop Timer Control
We can control the Timer Control Object that when it start its function as well as when it stop its function. The Timer Control has a start and stop methods to perform these actions.
Here is an example for start and stop methods of the Timer Control. In this example we run this program only 10 seconds. So we start the Timer in the Form_Load event and stop the Timer after 10 seconds. We set timer Interval property as 1000 milliseconds ( 1 second) and in run time the Timer will execute 10 times its Tick event .