Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Timers;
- namespace TimerApp
- {
- class Program
- {
- private static Timer aTimer;
- static void Main(string[] args)
- {
- // Create a timer and set a two second interval
- aTimer = new Timer();
- aTimer.Interval = 2000;
- // Hook up the Elapsed event for the timer.
- aTimer.Elapsed += OnTimedEvent;
- //Have the timer fire repeated events (true is the default)
- aTimer.AutoReset = true;
- //Start the timer
- aTimer.Enabled = true;
- Console.WriteLine("Press the Enter key to exit the program...");
- Console.ReadLine();
- }
- private static void OnTimedEvent(object source, ElapsedEventArgs e)
- {
- Console.WriteLine("Elapsed event was raised at: {0:HH:mm:ss}.", e.SignalTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement