I am developing an app in C++ that uses UIAutomation to receive notification of significant events related to user interaction. I have tried adding a structure changed event handler by calling AddStructureChangedEventHandler, but I am having problems stopping the notification and cleaning up before exiting. If the user has launched certain applications, such as Firefox, the call to RemoveStructureChangedEventHandler hangs. (Calling RemoveAllEventHandlers also hangs in this case.) I have also tried calling AddAutomationEventHandler with the event ID set to UIA_StructureChangedEventId, with the same result. (Other calls to AddAutomationEventHandler and associated Remove... calls work as expected. Calls to AddFocusChangedEventHandler and AddPropertyChangedEventHandler also work fine.) Note that all calls to add or remove event handlers are done in the context of the same non-UI thread.
Note: I am seeing this behavior on Windows 7 and on Windows 8.
Any ideas on why this is happening or how to fix it? What makes the structure changed event different from all the others?
Thanks.
Wayne