How to: Create Instances of Server-Based TimersĀ
You create Timer components when you want to build interval-based events into your multi-threaded application. You can add an instance of the Timer component to Web Forms, Windows Services, and component classes.
There are two ways you can create an instance of the Timer component:
You can drag an instance of the Timer component from the Components tab of the Toolbox to a form or other designer.
You can create an instance of the Timer component in code.
To create a Timer component from the Toolbox
On the Tools menu, click Choose Toolbox Items, and then click the .NET Framework Components tab.
In the Choose Toolbox Items dialog box, select the Timer check box in the System.Timers namespace. The Timer icon is added to the Components tab of the Toolbox.
Select the Timer icon, and drag it to the designer surface for your form or component.
In the Properties window, set the Interval property for your component instance to the length of time, in milliseconds, after which you want the component to raise an event.
Set the Enabled property for your component instance to true.
To create a Timer component programmatically
Create an instance of the Timer class.
Set the Interval property for your component instance to the length of time, in milliseconds, after which you want the component to raise an event.
Set the Enabled property for your component instance to true.
The following code shows how to create and configure a Timer component.
Dim myTimer As New System.Timers.Timer() myTimer.Interval = 3000 myTimer.Enabled = True
System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Interval = 3000; myTimer.Enabled = true;
System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.set_Enabled(true); myTimer.set_Interval(3000);
See Also
Tasks
How to: Monitor Server-Based Timers
Reference
Timer Component Overview (Windows Forms)