i've noticed that using peekmessage is just like using while(1) and totaly consumes the cpu, what's the best delay to put into the loop?
I was thinking sleep(0); what do you guys think?
This is a discussion on 100 cpu within the Windows Programming forums, part of the Platform Specific Boards category; i've noticed that using peekmessage is just like using while(1) and totaly consumes the cpu, what's the best delay to ...
i've noticed that using peekmessage is just like using while(1) and totaly consumes the cpu, what's the best delay to put into the loop?
I was thinking sleep(0); what do you guys think?
The standard non-busy message loop is:
If you want a delay in a PeekMessage() loop, yes you can use Sleep(1)(not Sleep(0)*) to give up the rest of the thread time slice when you have done whatever you need to do.Code:BOOL bRet; MSG msg; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } }
*Apparently, Sleep(0) will only yield to threads with the same or higher priorites, while Sleep(1) or above will yield to any thread.