in src/Desktop/UIAutomation/EventHandlers/EventListenerFactory.cs [78:143]
private void ProcessMessageQueue()
{
this.UIAutomation = new CUIAutomation();
// CUIAutomation8 was introduced in Windows 8, so don't try it on Windows 7.
// Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/hh448746(v=vs.85).aspx?f=255&MSPPError=-2147217396
if (!Win32Helper.IsWindows7())
{
this.UIAutomation8 = new CUIAutomation8();
}
_autoEventInit.Set();
// fCloseDown will be set true when the thread is to close down.
bool fCloseDown = false;
while (!fCloseDown)
{
// Wait here until we're told we have some work to do.
_autoEventMsg.WaitOne();
while (true)
{
EventListenerFactoryMessage msgData;
// Note that none of the queue or message related action here is specific to UIA.
// Rather it is only a means for the main UI thread and the background MTA thread
// to communicate.
// Get a message from the queue of action-related messages.
lock (_msgQueue)
{
if(_msgQueue.Count != 0)
{
msgData = _msgQueue.Dequeue();
}
else
{
break;
}
}
switch(msgData.MessageType)
{
case EventListenerFactoryMessageType.FinishThread:
// The main UI thread is telling this background thread to close down.
fCloseDown = true;
break;
case EventListenerFactoryMessageType.RegisterEventListener:
RegisterEventListener(msgData);
break;
case EventListenerFactoryMessageType.UnregisterEventListener:
UnregisterEventListener(msgData);
break;
case EventListenerFactoryMessageType.UnregisterAllEventListeners:
UnregisterAllEventListener();
break;
}
msgData.Processed();
}
}
_autoEventFinish.Set();
}