Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Question Timers and CPU Usage in C++

    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.

  • #2
    New Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Binary Invisions
    Where the Webmasters Go.
    www.binvisions.com

  • #3
    New Coder
    Join Date
    Nov 2004
    Location
    Netherlands
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe VC++ has something with timers, but this used up like 0 % of the CPU for me:

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    int main()
    {
    	MSG Message;
    	
    	SetTimer(NULL, NULL, (UINT)100, NULL);
    	
    	while(GetMessage(&Message, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&Message);
    		if(Message.message == WM_TIMER)
    		{
    			printf("..|");
    		}
    	}
    	
    	return 0;
    }

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Thanks Dr. Evil, code works fine!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •