My app takes 100% of the cpu cycle, HELP

Started by
2 comments, last by OverGround 19 years, 10 months ago
I recently wrote a program in visual C++ 6, all the program does is check the localTime against a text file of times and if they are equal executes a program. This is the same thing as the MS. Scheduler program. My question is, how come my app takes up 100% of the cpu cycles. All of the other game programs i have written do this and that is fine for a game, but for a windows app I dont want to take that many cycles just to check the loacl time. Why does the windows code take up 100% of the cpu cycles??
Im still here?
Advertisement
because you do nothing but loop and loop and loop and loop?

what did you expect to happen? the computer magically divines that it can stop processing in THIS thread for awhile because nothings changed in what its checking over and over and over again?

I suggest reading the file, calculating the time until the next time it has to do something, and then sleeping for that amount of time.
An even better solution to this is to use events and threading to accompish the same thing. look up the windows multimedia library to find a cool accurate timer function that you can have callback your program at certain times.

--------------------------------------

It took me long enough, but now I am finally 16. Yay! Sorta funny, but I am probably the only person on earth who wrote a 3D driving game prior to actually driving .
Try using the Win32 Sleep() function at the end of the loop, to allow some time to pass before running the code inside the loop again. Note Sleep() takes a time parameter in milliseconds (1/1000 of a second).

This topic is closed to new replies.

Advertisement