Posted By

rtipton on 10/31/09


Tagged

timer


Versions (?)

System.Timers.Timer Example


 / Published in: C#
 

1 of the 3 types of timers in the .net framework

  1. using System;
  2. using System.Timers;
  3.  
  4. public class Program
  5. {
  6. private static System.Timers.Timer testTimer;
  7.  
  8. public static void Main(string[] args)
  9. {
  10. testTimer = new System.Timers.Timer(5000); // 5 seconds
  11. testTimer.Elapsed += new ElapsedEventHandler(OnTimerElapsed);
  12.  
  13. testTimer.Interval = 5000;
  14. testTimer.Enabled = true;
  15.  
  16. Console.WriteLine("Press the enter key to stop the timer");
  17. Console.ReadLine();
  18.  
  19. }
  20.  
  21. private static void OnTimerElapsed(object source, ElapsedEventArgs e)
  22. {
  23. Console.WriteLine("Timer elapsed at {0}", e.SignalTime);
  24. }
  25. }

Report this snippet  

You need to login to post a comment.