Introduction
This article explains the Timer object and the properties of the Timer class in Windows Forms applications.
Timer Object
The Timer object allows users to set the time interval periodically to execute an event at a specified interval. The Timer object executes an event after a specifed interval. A Timer object raises an event at a given interval of time without using a secondary thread. The Timer class is a sealed class, in other words this class cannot be inherited.
Properties
The properties of Timer Objects are:
- Timer.AutoReset: AutoReset indicates that the timer should raise the elapsed event continuously after the specified interval each time
- Timer.Enabled: The Timer raises the elapsed event; you must set this to true if the timer is to do anything.
- Timer.Interval: The number of milliseconds between elapsed events being raised. The default interval time is 100 milliseconds.
- Timer.Start: Start raising the event by setting Enabled to true.
- Timer.Stop: Stop raising the event by setting Enabled to false.
- Timer.Close: Releases the resources used by the Timer.
Methods
The methods of the Timer Objects are:
- Dispose(): Releases all resources used by the current instance of the Timer object.
- ToString(): Returns a string that represents a current instance.
- GetType(): Gets the type of the current instance.
- Dispose(WaitHandle): Releases all resources used by the current instance of the timer and signals when the timer has been disposed of.
- Change(Int32 , Int32): Changes the start time and the interval between method invocations for a time.
Tick Event
The Tick Event handles when an action is performs during each postback and when the number of milliseconds specified in the "Interval" property of the timer class then the "Tick" event is raised.
Substring
Substring is the part of the string class that returns a new string that is a substring of the string. The substring begins at the specified given index and extended up to the given length. for example I have used Substring(10), in other words the number of characters in the substring.
Now I will show you how to use Timer object in a Windows Forms application. Let's use the following procedure.
Step 1:
Open Visual Studio then select "Create New Project" --> "F# Console Application".

Step 2:
Now go the Solution Explorer on the right side of the application. Right-click on "References" and select "Add references".


Step 3:
After selecting "Add References", in the framework template you need to select "System.Windows.Forms" and "System.Drawing" while holding down the Ctrl key and click on "Ok."

Step 4:
Write the following code Timer object records in the F# editor.


Join the conversation! Your thoughts help the community grow.