完整代码如下:
// page 273
using System;
using System.Timers;
// requied System.dll
//namespace ConApp5
//{
class Clock
{
static int iStringLenth;
[STAThread]
static void Main( )
{
Console.WriteLine("Press Enter to end program");
Console.WriteLine();
Timers tmr = new Timer();
tmr.Elapsed += new ElapsedEnentHandler(TimerHandler);
tmr.Interval = 1000;
tmr.Start();
Console.ReadLine();
tmr.Stop();
}
static void TimerHandler(object obj,ElapsedEventArgs eea)
{
Console.Write(new String('\b',iStringLenth));
string str = String.Format("{0} {1}",eea.SignalTime.ToLongDateString(),
eea.SignalTime.ToLongTimeString());
iStringLenth = str.Length;
Console.Write(str);
}
}
//}