Click here to Skip to main content
15,897,718 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SetTimer Pin
Erudite_Eric31-Oct-11 21:12
Erudite_Eric31-Oct-11 21:12 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 2:58
Chuck O'Toole1-Nov-11 2:58 
GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 3:07
Erudite_Eric1-Nov-11 3:07 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 3:18
Chuck O'Toole1-Nov-11 3:18 
GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 3:30
Erudite_Eric1-Nov-11 3:30 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 3:44
Chuck O'Toole1-Nov-11 3:44 
GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 4:48
Erudite_Eric1-Nov-11 4:48 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 5:11
Chuck O'Toole1-Nov-11 5:11 
[updated to reflect a third experiment's results]

Erudite__Eric wrote:

Of course there is! He wouldnt HAVE a Windows applicaiton without a message
pump!

I'm not that dumb. Maybe I should have said "no message pump for Sleep() to return to". Your statement that Sleep() will release the call to DispatchMessage() needs to be proven beyond simply asserting it is true so I ran an experiment.

I have a "regressison tester" application that does many long running things. In one case, similar to this one, I'm just cross checking some datafiles and I need to keep a "status / log window up to date with the progress". So I have this function called at times in the processing loop.
C#
void CRegressionTesterDlg::ProcessWindowMessages()
{
    MSG msg;

//  Sleep(0);
    while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))  // let them see the message before we go into longer term wait
    {
        TranslateMessage(&msg);                         // translate it
        DispatchMessage(&msg);                          // and let windows dispatch it to WinProc
    }
}


And I ran three tests, one with the code as originally written, once with Sleep() replacing the message loop, and once with all the code commentd out. All kept the window up to date when it was visible. However, the Sleep() case and the "no code" case both failed to process other windows messages, like minimizing, clicking on the task bar to bring the window back to the front, etc. All these are classic symptoms of not having the "message pump" run.

So, I think that Sleep() does not do as you assert, it has no effect on the Windows Message Processing. Furthermore, Microsoft's documentation on Sleep() explicitly warns against using it during functions called by message processing as it may cause a hang or delay in processing.

Personally, since Microsoft says to use PeekMessage() in their documentation for exactly these types of long running things, I'm sticking with that. And I think you need to run some experiments on your own.

modified 1-Nov-11 11:23am.

GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 6:43
Erudite_Eric1-Nov-11 6:43 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 7:51
Chuck O'Toole1-Nov-11 7:51 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Goto_Label_1-Nov-11 9:17
Goto_Label_1-Nov-11 9:17 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Chuck O'Toole1-Nov-11 10:14
Chuck O'Toole1-Nov-11 10:14 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Erudite_Eric2-Nov-11 7:02
Erudite_Eric2-Nov-11 7:02 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Chuck O'Toole2-Nov-11 9:16
Chuck O'Toole2-Nov-11 9:16 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Erudite_Eric2-Nov-11 11:25
Erudite_Eric2-Nov-11 11:25 
Generale: SetTimer Pin
Erudite_Eric1-Nov-11 22:06
Erudite_Eric1-Nov-11 22:06 
GeneralRe: SetTimer Pin
David Crow1-Nov-11 9:29
David Crow1-Nov-11 9:29 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 10:16
Chuck O'Toole1-Nov-11 10:16 
AnswerRe: SetTimer Pin
Mark Salsbery31-Oct-11 12:32
Mark Salsbery31-Oct-11 12:32 
GeneralRe: SetTimer Pin
Chuck O'Toole31-Oct-11 12:59
Chuck O'Toole31-Oct-11 12:59 
GeneralRe: SetTimer Pin
Mark Salsbery31-Oct-11 14:48
Mark Salsbery31-Oct-11 14:48 
GeneralRe: SetTimer Pin
Chuck O'Toole31-Oct-11 15:00
Chuck O'Toole31-Oct-11 15:00 
GeneralRe: SetTimer Pin
Erudite_Eric31-Oct-11 21:08
Erudite_Eric31-Oct-11 21:08 
GeneralRe: Thanks!!! Pin
columbos1492731-Oct-11 21:44
columbos1492731-Oct-11 21:44 
AnswerRe: example code with PumpMessages() Pin
App_1-Nov-11 8:53
App_1-Nov-11 8:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.