日期:2014-05-17  浏览次数:20898 次

Thread.sleep() 为什么暂停时间不对?
我用Thread.sleep(2000),要暂停程序2秒钟,可是我发现暂停的时间根本没有2秒,有的时候很快就到了。我把时间设置大点,如5000毫秒,还是一样的。这是怎么回事?如精确的控制暂停的时间呢?

------解决方案--------------------
Thread.CurrentThread.Join(2000);

------解决方案--------------------
lz看看这个帖子:

What Thread sleep method is most precise: Monitor.Wait vs System.Timer vs DispatchTimer vs Threading.Timer
http://stackoverflow.com/questions/10609718/what-thread-sleep-method-is-most-precise-monitor-wait-vs-system-timer-vs-dispat

How accurate is Thread.Sleep(TimeSpan)?
http://stackoverflow.com/questions/1303667/how-accurate-is-thread-sleeptimespan