![](/img/trans.png)
[英]What is the best way to wait for a certain time (say 10 seconds) in C#?
[英]What is the best way to wait in C#?
我正在制作一個控制台應用程序,該程序僅執行幾個命令,例如whoami
。 我遇到的問題是如何使“ Please wait...
等待X(例如5)秒而不停止線程,然后繼續
您可以使用單次計時器來執行此操作。 例如:
static int main(...)
{
System.Threading.Timer clearTimer = new System.Threading.Timer(
(s) => { Console.Clear(); },
null,
5000,
Timeout.Infinite);
// do other stuff
}
這將創建一個計時器,該計時器將在五秒鍾后觸發一次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.