Use the Timer to trigger event : Timer : Development C# Examples


C# Examples » Development » Timer »

 

Use the Timer to trigger event









    
using  System;
using  System.Timers;
using  System.ServiceProcess;

class  MainClass
{

        private  static  void  WriteLogEntry(object  sender,  ElapsedEventArgs  e)
        {
                Console.WriteLine("Timer  is  active  :  "  +  e.SignalTime);
        }

        public  static  void  Main()
        {
                System.Timers.Timer  timer  =  new  Timer();
                
                double  interval  =  1000;

                timer.Interval  =  interval;
                timer.AutoReset  =  true;
                timer.Elapsed  +=  new  ElapsedEventHandler(WriteLogEntry);
                timer.Start();

                Console.ReadLine();
        }
}
    
   
  
   



Output

Timer is active : 25/03/2007 2:16:08 PM
Timer is active : 25/03/2007 2:16:09 PM
Timer is active : 25/03/2007 2:16:10 PM
Timer is active : 25/03/2007 2:16:11 PM
^CTerminate batch job (Y/N)? n


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Timer