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
Post a Comment