Timer Callbacks C# with Example



Timer Callbacks C# with Example

 using System;
using System.Threading;

namespace CSharpMultiThreading
{
	class Program
	{
		static void PrintTime(object state)
		{
			Console.WriteLine("Time is: {0}", DateTime.Now.ToLongTimeString());
		}
		
		static void Main(string[] args)
		{
			// Create the delegate for the Timer type.
			TimerCallback timeCB = new TimerCallback(PrintTime);
		
			// Establish timer settings.
			Timer t = new Timer(
			timeCB, 				// The TimerCallback delegate object.
			null, 					// Any info to pass into the called method (null for no info).
			0, 						// Amount of time to wait before starting (in milliseconds).
			1000); 					// Interval of time between calls (in milliseconds).
			Console.WriteLine("Hit key to terminate...");
			Console.ReadLine();
		}
	}
} 

0 Comment's

Comment Form

Submit Comment