Click to See Complete Forum and Search --> : Best way to exit a UI and Worker thread
Brooks Younce
August 14th, 2005, 12:31 PM
I have used many techniques in the past, but I am just wondering,
with a standard Dialog Interface MFC App.
What would be the best way, when exiting the app,
to wait for a UI thread to exit, without freezing the dialog thread.
Also what would be the best way to do the same thing with a worker thread.
Thanks!
golanshahar
August 14th, 2005, 04:12 PM
How to end a thread? (http://www.codeguru.com/forum/showthread.php?t=305166)
Cheers
Brooks Younce
August 15th, 2005, 12:02 AM
Those are both good ways, but they still can freeze the dialog during exit.
What I have done in the past is call PeekAndPump during long loops in UI threads, so I dont have to force terminate anything.
And also when dealing with multiple UI threads, I would create a worker thread when exiting the program that would wait for all the UI threads to exit, that way if the UI threads needed to post messages to the main dlg, or access the main dlg's variables before closing, they could. then after the worker thread exited, the app exited. this would prevent the main dlg from freezing when exiting a lot of threads.
was just wondering what everyone else did in such cases.
Thanks
kirants
August 19th, 2005, 03:13 PM
If the look of the main dialog is a problem, just before the wait-on-all-threads-to-finish code, probably you can try hiding the dialog altogether ??? Just thinking..
kuphryn
August 20th, 2005, 01:34 AM
There is no best way for this task. If your solution works without slowing the termination time much, then there is no need for a different solution.
Kuphryn
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.