如何使用Sleep或Timer我有两种选择,使用定时器或使用睡眠,我需要在这个方法完成后每3秒调用一个方法,我写了一个基本的例子来证明我的意思:publicstaticvoidMain(){newThread(newThreadStart(fooUsingSleep)).Start();callToMethodAfterInterval(新动作(fooUsingTimer),3000);}publicstaticvoidfooUsingSleep(){Console.WriteLine("使用睡眠做一些耗时的工作");线程.睡眠(3000);fooUsingSleep();}publicstaticvoidfooUsingTimer(objectdummy,ElapsedEventArgsdummyElapsed){Console.WritesLine("Doconsumingtimeworkusningtimer");callToMethodAfterInterval(新动作(fooUsingTimer),3000);}publicstaticvoidcallToMethodAfterInterval(ActioninMethod,intinInterval){System.Timers.TimermyTimer=newSystem.Timers.Timer();我的计时器。Elapsed+=newElapsedEventHandler(inMethod);myTimer.Interval=inInterval;myTimer.AutoReset=false;我的计时器开始();所以我的问题是1)我可以用更优雅的计时器编写代码吗?意思是去掉fooUsingTimer对callToMethodAfterInterval方法的调用,使得计时undefined
