- // we can't just wait for the thread to terminate because it might be
- // calling some GUI functions and so it will never terminate before we
- // process the Windows messages that result from these functions
- DWORD result;
- do
- {
- result = ::MsgWaitForMultipleObjects
- (
- 1, // number of objects to wait for
- &hThread, // the objects
- FALSE, // don't wait for all objects
- INFINITE, // no timeout
- QS_ALLEVENTS // return as soon as there are any events
- );
-
- switch ( result )
- {
- case 0xFFFFFFFF:
- // error
- wxLogSysError(_("Can not wait for thread termination"));
- Kill();
- return (ExitCode)-1;
-
- case WAIT_OBJECT_0:
- // thread we're waiting for terminated
- break;
-
- case WAIT_OBJECT_0 + 1:
- // new message arrived, process it
- if ( !wxTheApp->DoMessage() )
- {
- // WM_QUIT received: kill the thread
- Kill();
-
- return (ExitCode)-1;
- }
-
- if ( IsMain() )
- {
- // give the thread we're waiting for chance to exit
- // from the GUI call it might have been in
- if ( (s_nWaitingForGui > 0) && wxGuiOwnedByMainThread() )
- {
- wxMutexGuiLeave();
- }
- }
-
- break;
-
- default:
- wxFAIL_MSG(wxT("unexpected result of MsgWaitForMultipleObject"));
- }
- } while ( result != WAIT_OBJECT_0 );
+#if wxUSE_GUI
+ // simply wait for the thread to terminate
+ while( TestDestroy() )
+ {
+ ::YieldToAnyThread() ;
+ }
+#else // !wxUSE_GUI
+ // simply wait for the thread to terminate
+ while( TestDestroy() )
+ {
+ ::YieldToAnyThread() ;
+ }
+#endif // wxUSE_GUI/!wxUSE_GUI