On Mar 21, 9:43 pm, David Wilkinson <no-re...@effisols.com> wrote:
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
hi david,
these are the simple rules people follow to avoid UI hanging problem.
i am putting the steps below..
1) main GUI thread is busy..
2) during main thread busy i am doing some more click or draging the
UI
3) OS puts the message in the message queue for steps 2 and messages
not picking up by GUI main thread
r u meaning OS doing sendmessage() and since if the GUI thread not
releasing the OS call it gets hangs??
but i think OS put the messages in the queue and leave it to the GUI
thread to process.
i am not clear in that level what happens in step 3 which makes the UI
hangs..
Aditya
#1 should never happen. The GUI thread should never be busy. Otherwise it
won't process the messages in step #3 caused by user interaction in step #2.
So fix #1.