1 min read

Working with timers in .NET Part 1 – Instantiate the timer object

Let’s use the Timer class in .NET here.

First let’s create a static field, aTimer.

private static System.Timers.Timer aTimer;

Next create a new method that creates a timer and enables it to raise an event.

private static void SetTimer() 
    aTimer = new Timer(2000);
    aTimer.Enabled = true;
    aTimer.AutoReset = true;

Finally call the method inside the Main method.

Great! In the next post let’s hook up the timer to an event.

Leave a Reply