the 9th line will execute after 2 sec as you have written
"System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, null, 0, 2000);"
and your program will get closed in just 1 second as you have called
"System.Threading.Thread.Sleep(1000);"
if you call 9th line multiple time like this
class Program
{
static void Main(string[] args)
{
System.Threading.TimerCallback TimerDelegate =
new System.Threading.TimerCallback(TimerTask);
System.Threading.Timer TimerItem = new System.Threading.Timer(TimerDelegate, null, 1, 4000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(1000);
}
private static void TimerTask(object StateObj)
{
Console.WriteLine(DateTime.Now.ToString());
}
}
it will show result
NOTE:your program will close as the last "Thread.Sleep" would be executed