Any difference between kernel32.dll Sleep and Thread.Sleep()

陌路散爱 提交于 2019-12-12 11:01:27

问题


Is there any difference(performance, implementation. .whatever) between the following:

i)

DllImport("kernel32.dll")]
        public extern static void Sleep(uint msec);

..then call Sleep function

ii)

Thread.Sleep()

回答1:


There's a big difference, actually.

This blog post explains why managed threads should never do unmanaged blocking, if possible. The official MSDN documentation has the same guideline without all the underlying details.

P.S. Thread.Sleep is a sign of a poorly-designed program.




回答2:


I wouldn't think so. They both work on the current thread only.

Take care though when using the Sleep function in the main thread as programs that depend on synchronized timing usually cause problems when external configurations change.

Using Sleep in support or listening threads is usually not a problem though.



来源:https://stackoverflow.com/questions/5153005/any-difference-between-kernel32-dll-sleep-and-thread-sleep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!