static void PrintTime(object data)
{
System.Console.WriteLine("date: " + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "data: " + data);
}
static void Main(string[] args)
{
try
{
TimerCallback timeCB = new TimerCallback(PrintTime);
Timer t = new Timer(timeCB, "demo", 0, 1000);
}catch(Exception ex)
{
System.Console.WriteLine("Message: " + ex.Message);
System.Console.WriteLine("StackTrace: " + ex.StackTrace);
System.Console.WriteLine("Name: " + ex.TargetSite.Name);
}
System.Console.ReadLine();
}
结果: