Create the delegate that the Timer will call : Timer : Development C# Examples


C# Examples » Development » Timer »

 

Create the delegate that the Timer will call









    
using  System;
using  System.Threading;

class  MainClass
{
    public  static  void  CheckTime(Object  state)  
    {
        Console.WriteLine(DateTime.Now);
    }

    public  static  void  Main()  
    {
        TimerCallback  tc  =  new  TimerCallback(CheckTime);

        
        Timer  t  =  new  Timer(tc,  null,  1000,  500);

        Console.WriteLine("Press  Enter  to  exit");  
        int  i  =  Console.Read();

        //  clean  up  the  resources
        t.Dispose();
        t  =  null;
    }
}
    
   
  
   



Output

Press Enter to exit
 25/03/2007 2:27:10 PM
25/03/2007 2:27:10 PM
 25/03/2007 2:27:10 PM
 25/03/2007 2:27:11 PM


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Timer