Friday, April 25, 2014

Thread.Sleep freezing my program in c#

What sort of delay are you expecting?


The argument to Sleep is the number of milliseconds delay, so if you set that to, say, 500 and the while loop is executed, say, 100 times, this would make your application freeze for 50 seconds.


And Mike is right about using timers instead. Thread.Sleep is often used by beginners, but it can be a trap, and legitimate real world uses for it are extremely rare.


No comments:

Post a Comment