C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How does Sleep sleep? Posted by VanilleBert on 14 Feb 2006 at 12:17 AM
Hi,

first look what I mean with Sleep and MySleep.

Sleep:
System.Threading.Thread.Sleep(5000);


MySleep:
DateTime DT = DateTime.Now;
while (((TimeSpan)(DateTime.Now - DT)).TotalMilliseconds < 5000) ;


If you use Sleep, you will see no CPU-Usage-Maximum in the TaskManager.
But if you use MySleep, the CPU will reach a usage max. I understand why MySleep use the CPU, but why does Sleep don't?

How does Sleep sleep?
Report
Re: How does Sleep sleep? Posted by weicco on 14 Feb 2006 at 12:23 AM
I think Sleep calls for Win32 API function Sleep which then tells Operating System "this thread is sleeping now for 5000 ms." After this process scheduler (this gets really deep into OS) schedules sleeping thread away and sets another thread into run. When scheduler has gone through every thread in the system it sees our sleeping thread. It checks if its still sleaping and if not, it starts scheduling some processor time for it again.
Report
Re: How does Sleep sleep? Posted by VanilleBert on 14 Feb 2006 at 5:04 AM
: I think Sleep calls for Win32 API function Sleep which then tells Operating System "this thread is sleeping now for 5000 ms." After this process scheduler (this gets really deep into OS) schedules sleeping thread away and sets another thread into run. When scheduler has gone through every thread in the system it sees our sleeping thread. It checks if its still sleaping and if not, it starts scheduling some processor time for it again.
:

Thx for this. My thirst for knowledge is satisfied.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.