Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

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

  1. On the Tools menu, click Choose Toolbox Items, and then click the .NET Framework Components tab.

  2. 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.

  3. Select the Timer icon, and drag it to the designer surface for your form or component.

  4. 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.

  5. Set the Enabled property for your component instance to true.

To create a Timer component programmatically

  1. Create an instance of the Timer class.

  2. 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.

  3. Set the Enabled property for your component instance to true.

    The following code shows how to create and configure a Timer component.

    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

Community Additions

ADD
Show:
© 2015 Microsoft