c# - Thread.Sleep - how to use it in a proper way? -


system.threading.thread.sleep(1000); pauses whole program 1 second, when second on done period. example:

thread.sleep(1000); console.writeline("a"); thread.sleep(1000); console.writeline("b"); 

it wait 2 seconds , write

a
b

how use pause properly?

thread.sleep() behaves think; pauses current thread approximately given number of milliseconds.

the problem here standard output stream not flush console (or wherever pointed at) on each call write. instead, may buffer content write out in larger chunks efficiency. try calling console.out.flush(); after each writeline() , should see results expect.


Comments

Popular posts from this blog

php - How to serve a file for download on WordPress -

how to share virtual sharepoint server and get it in host windows and visual studio? -