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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -