This is about programming, but it's about VB programming instead of empeg programming. But since it's about the EmpegFace program I'm trying to get working properly, I think it's OK to post it here.

The question: How to get a proper "relax and let things go" loop written that doesn't appear to consume 99% CPU in Task Manager when it's idle.

The standard thing in VB is to put the DoEvents statement in your loop. This allows messages to get processed by other programs (and elsewhere in your own program) whenever needed, yet allows your loop to continue. This works fine, doesn't slow down other programs, and still leaves your program responsive within the loop.

Except that when your program is idle and looping, and nothing else is doing anything important on the system, then Task Manager shows your idle loop consuming 99 percent CPU time, instead of the system idle process doing it. This produces complaints from your users.

The other way around this is to re-architect your program so that it doesn't need the idle loop. For example, using a timer to do the idling. Let's assume for a moment that I can't do this for various reasons. I'm already using timers for some things and in this particular case I've got my reasons for not wanting to use a timer.

Googling for solutions gives me replacement idle loops which call the Windows API functions GetMessage or PeekMessage. These work, but there is a problem: When I use the PeekMessage alternatives, the result is exactly the same as DoEvents: Idle loops consume 99 percent CPU time (in fact I think this behavior is an indication that DoEvents really is just a PeekMessage loop under the hood). When I use the GetMessage alternative, my program sits there and locks up waiting for a message (since in my idle loop, I'm not getting any messages, and the GetMessage alternatives only perform an action when there is a message to get).

Anyone got any ideas, or can you point me to any example code variations that use GetMessage and/or PeekMessage in ways that are satisfactory?
_________________________
Tony Fabris