Re: why UI gets hangs
Aditya wrote:
That is the main reason to keep the primary UI free: to process messages.
Messages from other threads, or messages caused by user actions.
I'm not quite sure what is confusing you.
--
David Wilkinson
Visual C++ MVP
hi David,
ya u r correct ..we need to keep the primary thread free to process
messages,
messages from other threads or messages caused by user actions but my
question is if i block
it and during that period did some UI operation from other
threads..why UI get hangs...is there any reason special reason like
need
to process the message immediately
Aditya:
It is a design mistake to try to alter the GUI directly from a secondary thread.
Apart from anything else, most GUI functions use SendMessage() internally, and
if the windows were created in the main thread and you block that thread, the
messages will not be delivered. Perhaps this is the answer you were looking for?
In MFC there are additional reasons not to access GUI components from secondary
threads; in particular the map from HWND's to CWnd's is maintained on a per
thread basis.
All these problems can be avoided by these simple rules:
1. Never block the main thread.
2. Never create GUI components in secondary threads.
3. Always have secondary threads use PostMessage() (or SendMessage() if you are
careful) to transmit information to the main thread, so the main thread can
update the GUI.
--
David Wilkinson
Visual C++ MVP