2014-07-16 76 views
0

我正在制作一个控制台应用程序,只执行几个命令,如whoami。我碰到的问题是如何使Please wait...在不停止线程的情况下等待X(例如5)秒,然后继续在C#中等待的最佳方式是什么?

+0

运行什么样的事件循环以避免冻结? – SLaks

+0

我没有使用任何方法 – td512

回答

4

您可以使用一次性计时器来执行此操作。例如:

static int main(...) 
{ 
    System.Threading.Timer clearTimer = new System.Threading.Timer(
     (s) => { Console.Clear(); }, 
     null, 
     5000, 
     Timeout.Infinite); 
    // do other stuff 
} 

这会创建一个定时器,它会在五秒钟后触发一次。

+0

谢谢你,+1 – td512

相关问题