简体   繁体   中英

What is the best way to wait in C#?

I am making a console application that is to execute only a couple of commands such as whoami . The issue i am coming up against is how to make Please wait... Wait X (eg 5) seconds without halting the thread, then continue

You can use a one-shot timer to do it. For example:

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

That creates a timer that will fire once after five seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM