Search code examples
c#thread-sleep

How to set timeout in C#


I would like to ask how to do it in my console application in C# to program must wait 3 seconds. For example, the program displays the line Console.WriteLine("Hello!"); the program then wait 3 seconds and then writes the next line: Console.WriteLine("Welcome to my program.");.


Solution

  • This can be done by:

    Console.WriteLine("Hello!");
    System.Threading.Thread.Sleep(3000);
    Console.WriteLine("Welcome to my program.");