Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i put a delay with C#?

I want to make an application to execute several instructions to pass the following instruction has to wait a few milliseconds.

Such that:

while(true){

  send("OK");
  wait(100); //or such delay(100);

}

Is it possible in C#?

like image 977
FredVaz Avatar asked Feb 09 '12 14:02

FredVaz


2 Answers

Thread.Sleep(100); will do the trick. This can be found in the System.Threading namespace.

like image 161
Neil Knight Avatar answered Sep 27 '22 18:09

Neil Knight


You can use the Thread.Sleep() method to suspend the current thread for X milliseconds:

// Sleep for five seconds
System.Threading.Thread.Sleep(5000);
like image 25
Christofer Eliasson Avatar answered Sep 27 '22 18:09

Christofer Eliasson