View Full Version : Timers and CPU Usage in C++

02-12-2005, 01:27 AM
Hello, I have a win32 app in VC++ 6.0. I have created a timer and TimerProc function. All I want the program to do is sit there while the timer ticks away. The problem is that there is no way to do this without CPU usage on my process jumping to 99%. I have tried Google, and the first result was this very question. The problem was the code was a little involved and I really don't understand it completely as it's not well commented or explained. If you need code I can get it (though I don't see why you would...). Thanks in advance, dunna.

02-12-2005, 05:50 AM
CPU usage jumps to 99% for like anything.. I think your CPU will always try to dedicate itself to any number of processes. This goes beyond my knowledge, but do you lag when you do other things WHILE having this application open? If not, I wouldn't worry about it.

Dr. Evil
02-12-2005, 09:32 AM
Maybe VC++ has something with timers, but this used up like 0 % of the CPU for me:

#include <stdio.h>
#include <windows.h>

int main()
MSG Message;

SetTimer(NULL, NULL, (UINT)100, NULL);

while(GetMessage(&Message, NULL, 0, 0) > 0)
if(Message.message == WM_TIMER)

return 0;

02-12-2005, 02:59 PM
Thanks Dr. Evil, code works fine! :thumbsup: