Click here to Skip to main content
15,880,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my dynamic library, I created a thread and registered a structure change event handler by calling IUIAutomation::AddStructureChangedEventHandler for the desktop root node. The thread is always running.
When I do not call the anti-registration function (StopFocusChangedEventListening), clicking to exit the program will affect the program's normal call of TerminateProcess and ExitProcess, and the program's window will be destroyed (WM_DESTROY), but the background cannot exit, and the program will not exit until dozens of seconds later. Forcefully kill the thread and exit;
When I first call the anti-registration function (StopFocusChangedEventListening) and then click to exit, the program exits normally;
Now my problem is that I want to call the anti-registration function (StopFocusChangedEventListening) when the program exits, but this will affect the normal exit of the program. What should I do?

What I have tried:

Monitor the WM_DESTROY message of the main window, first call the anti-registration function (StopFocusChangedEventListening) and then distribute the DESTROY message, but it has no effect
Posted

1 solution

Read and implement the threading model correct as described in Understanding Threading Issues. Pay attention to the different threading appartment models which are cumbersome. Follow that article because it is the only way it will work.

Good luck - you will need it.

tip: it may better to recreate the project with the wizard to get the correct settings and IDL files. Long times ago I came to that experience after fiddling for a while.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900