Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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()
like image 366
Shamim Hafiz - MSFT Avatar asked Nov 14 '22 02:11

Shamim Hafiz - MSFT


1 Answers

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.

like image 192
Stephen Cleary Avatar answered Nov 16 '22 22:11

Stephen Cleary