Mega Code Archive

 
Categories / C# Tutorial / Development
 

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;   } } 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