@@ -193,14 +193,25 @@ DWORD WINAPI inprocMgrThreadFunc(LPVOID data) {
193193 // Even though we only registered for in-context winEvents, we may still receive some out-of-context events; e.g. console events.
194194 // Therefore, we must have a message loop.
195195 // Otherwise, any out-of-context events will cause major lag which increases over time.
196- do {
197- // Consume and handle all pending messages.
198- MSG msg;
199- while (PeekMessage (&msg,NULL ,0 ,0 ,PM_REMOVE )) {
200- TranslateMessage (&msg);
201- DispatchMessage (&msg);
196+ while (true ) {
197+ const long handleCount=1 ;
198+ const long WAIT_PENDING_MESSAGES =WAIT_OBJECT_0 +handleCount;
199+ DWORD res=MsgWaitForMultipleObjectsEx (handleCount,&nvdaUnregisteredEvent,INFINITE ,QS_ALLINPUT ,MWMO_ALERTABLE );
200+ if (res==(WAIT_PENDING_MESSAGES )) {
201+ // Consume and handle all pending messages.
202+ MSG msg;
203+ while (PeekMessage (&msg,NULL ,0 ,0 ,PM_REMOVE )) {
204+ TranslateMessage (&msg);
205+ DispatchMessage (&msg);
206+ }
207+ continue ;
208+ } else if (res==WAIT_IO_COMPLETION ) {
209+ // Woke for a queued APC function. Keep going.
210+ continue ;
202211 }
203- } while (MsgWaitForMultipleObjects (1 ,&nvdaUnregisteredEvent,FALSE ,INFINITE ,QS_ALLINPUT )==WAIT_OBJECT_0 +1 );
212+ // anything else (the registrationEvent was set, there was an error) means we need to stop.
213+ break ;
214+ }
204215 nhAssert (inprocMgrThreadHandle);
205216 inprocThreadsLock.acquire ();
206217 CloseHandle (inprocMgrThreadHandle);
0 commit comments