Use Timer : Timer : Development C# Examples


C# Examples » Development » Timer »

 

Use Timer









    
using  System;
using  System.Threading;

public  class  MainClass
{
        private  static  void  TimerProc(  object  state  )  {
                Console.WriteLine(  "The  current  time  is  {0}  on  thread  {1}",
                                                      DateTime.Now,
                                                      Thread.CurrentThread.GetHashCode()  );
                Thread.Sleep(  300  );
        }

        static  void  Main()  {
                Timer  myTimer  =  new  Timer(  new  TimerCallback(TimerProc),  null,  0,  2000  );

                Thread.Sleep(3000);
                myTimer.Dispose();
        }
}
    
   
  
   



Output

The current time is 25/03/2007 2:17:43 PM on thread 4
The current time is 25/03/2007 2:17:45 PM on thread 4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Timer