using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
class MyApp
{
private static bool TickNext = true;
public static void Main()
{
Console.WriteLine("Press Enter to terminate...");
TimerCallback callback = new TimerCallback(TickTock);
Timer timer = new Timer(callback, null, 1000, 1000);
Console.ReadLine(); //为什么 按 enter 键结束?? 拖延程序执行时间,没有这行,看不什么结果。
}
private static void TickTock(object state)
{
Console.WriteLine(TickNext ? "Tick" : "Tock");
TickNext = !TickNext;
}
}
评论