Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If this code is running on a UI thread, you will cause performance problems with other processes that (directly or indirectly) send messages to your window(s), since you do not run the message loop while you are waiting for the child process. Neither <a href="http://msdn.microsoft.com/en-us/library/ms686298(VS.85).aspx" rel="nofollow noreferrer">Sleep()</a> nor <a href="http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx" rel="nofollow noreferrer">WaitForSingleObject()</a> will process messages.</p> <p>Windows Explorer (the file manager) will not suffer this problem because it:</p> <ol> <li>Does not keep an open handle to processes it launches at the user's request (I think this is more likely, since Explorer needs neither to know when the process exits or its exit code), or</li> <li>Does not wait on any open process handles it may keep from its children, and importantly</li> <li>Always makes sure to run a message loop while it waits on handles. This is very important in any process that makes use of COM, which Explorer uses heavily.</li> </ol> <p>Instead of calling WaitForSingleObject(), you can call <a href="http://msdn.microsoft.com/en-us/library/ms684242(VS.85).aspx" rel="nofollow noreferrer">MsgWaitForMultipleObjects()</a>. If you specifiy QS_ALLINPUT for the dwWaitMask parameter, MsgWaitForMultipleObjects will return either when your event is signaled or when there is input in the thread's message queue. If MsgWaitForMultipleObjects() returned because a message is available, you can process it and resume waiting:</p> <pre><code>MSG msg; DWORD reason = WAIT_TIMEOUT; while (WAIT_OBJECT_0 != reason) { reason = MsgWaitForMultipleObjects(1, &amp;hChildProcess, FALSE, INFINITE, QS_ALLINPUT); switch (reason) { case WAIT_OBJECT_0: // Your child process is finished. break; case (WAIT_OBJECT_0 + 1): // A message is available in the message queue. if (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); // Note that if your main message loop does additional processing // (such as calling IsDialogMessage() for modeless dialogs) // you will want to do those things here, too. } break; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload