How can I add a delay to a program in C#?
You could use Thread.Sleep()
function, e.g.
int milliseconds = 2000;
Thread.Sleep(milliseconds);
that completely stops the execution of the current thread for 2 seconds.
Probably the most appropriate scenario for Thread.Sleep
is when you want to delay the operations in another thread, different from the main e.g. :
MAIN THREAD --------------------------------------------------------->
(UI, CONSOLE ETC.) | |
| |
OTHER THREAD ----- ADD A DELAY (Thread.Sleep) ------>
For other scenarios (e.g. starting operations after some time etc.) check Cody's answer.