×
Home About Us Products Services News Free Scripts Contact
news php scripts and software

C# (C Sharp) example - How to create and use System.Timers.Timer object


C# (C Sharp) - How to create and use System.Timers.Timer object

This example shows you how to create and use a Timer object.
The example will print "Hello" every second.


// create the timer set the event handler
Timer timer = new Timer();

// set the event handler
timer.Elapsed += new
ElapsedEventHandler(OnElapsed);

// set the timer properties
timer.Interval = 1000;
timer.AutoReset = true;

// start the timer
timer.Start();


void OnElapsed(Object sender, ElapsedEventArgs e)

{
    // on timeout this code is executed
    Console.WriteLine("Hello!");
}

Category: C# (C Sharp)

 
<< Go back