+bool wxEventLoopManual::ProcessEvents()
+{
+ // process pending wx events first as they correspond to low-level events
+ // which happened before, i.e. typically pending events were queued by a
+ // previous call to Dispatch() and if we didn't process them now the next
+ // call to it might enqueue them again (as happens with e.g. socket events
+ // which would be generated as long as there is input available on socket
+ // and this input is only removed from it when pending event handlers are
+ // executed)
+ if ( wxTheApp )
+ {
+ const bool hadExitedBefore = m_shouldExit;
+
+ wxTheApp->ProcessPendingEvents();
+
+ // One of the pending event handlers could have decided to exit the
+ // loop so check for the flag before trying to dispatch more events
+ // (which could block indefinitely if no more are coming).
+ if ( !hadExitedBefore && m_shouldExit )
+ {
+ // We still need to dispatch any remaining pending events, just as
+ // we do in the event loop in Run() if the loop is exited from a
+ // normal event handler.
+ while ( wxTheApp->HasPendingEvents() )
+ wxTheApp->ProcessPendingEvents();
+
+ return false;
+ }
+ }
+
+ return Dispatch();
+}
+