Create a Timer that runs twice a second, starting in one second : Timer : Development C# Examples


C# Examples » Development » Timer »

 

Create a Timer that runs twice a second, starting in one second









    
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


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Timer