What's the name of the function that a process can call to release the rest of its timeslice?

I'm writing a program that suspends itself when the user switches away from it, and it seems to be a waste for the program to be using 97% of my CPU cycles running the message pump and waiting for the window to gain focus again. I figure that, if the process is suspended and there are no messages pending, the program should be able to tell the kernel to let other processes have a bigger share. I know I've seen something about it somewhere, but I can't remember what it was or where I saw it, and all my searches turn up blank.
Posted on 2003-09-21 07:10:03 by Tatterdemalian
would a loop to check if your window has focus and invoke Sleep,0
if it's not, work?
Posted on 2003-09-21 10:24:42 by ASMMike
There was such a function, I don't remember the name either but it was in the WIN32.HLP file. It was NT-only, though. Anyway Sleep,0 should work fine, as stated by ASMMike.

Anyway it's strange.. mind if I ask, what do you mean "switching away from it"? GUI applications do not really need to call functions like this since GetMessage already puts the calling thread in a suspended state until an input event occurs.
Posted on 2003-09-22 14:19:31 by QvasiModo

There was such a function, I don't remember the name either but it was in the WIN32.HLP file. It was NT-only, though. Anyway Sleep,0 should work fine, as stated by ASMMike.

Guess you're talking about SwitchToThread ;)
Posted on 2003-09-22 19:22:58 by Tola


Guess you're talking about SwitchToThread ;)

Yes, that was it. :)
Posted on 2003-09-23 10:18:37 by QvasiModo
Anyway it's strange.. mind if I ask, what do you mean "switching away from it"? GUI applications do not really need to call functions like this since GetMessage already puts the calling thread in a suspended state until an input event occurs.

It's for a multimedia demo using DirectX. Anyhow, I tried using Sleep, 0, but for some reason it doesn't seem to return any cycles at all. My program still eats up 95% of the resources, even though it's supposed to be suspended. Maybe I should use Sleep, 1000 to make sure the program sleeps for one second between PeekMessage checks?
Posted on 2003-10-01 01:01:28 by Tatterdemalian
Testing shows that invoking Sleep, 1000 produces the desired result (no cycles used on program suspension) but causes a long delay when switching back to the program. Calling Sleep, 100 produces the same result and allows faster switching.

Thanks for the help!
Posted on 2003-10-01 01:22:41 by Tatterdemalian
Using a event object maybe.
involving CreateEvent, WaitForSingleObject ...
Posted on 2003-10-01 10:08:13 by optimus