Re: why UI gets hangs
I think this may be the biggest confusion. I know I still get caught by
this at times. It is so easy to put in something like AfxMessageBox() into
the worker thread and that just gets me (and I assume others) into trouble.
It works sometimes, but... I've also been caught when I tried to do that
sort of thing (UI) from a callback from a DLL function (like a message
server listener) which may (even though I don't know it) be running on its
own thread. My personal opinion these days is when in doubt send a message
to the UI thread. I also never call functions direction in dialogs or views
(except through UpdateAllViews()). This is a tough thing to get used to
since it's so easy to just grab a view pointer and call a function in the
class to update some text or whatever, but over all it really cleans the
code up when you just don't do this sort of thing and, instead, send a
message. I've found that that messages typically get processed immediately
if the bandwidth is clear so the net effect on the user's experience is the
same, but the program runs much better and more reliably. Nothing like
popping up an AfxMessageBox() with no text in it because the DLL thread has
it's own resources :o)
I know you agree, I'm just adding comments to the thread (forum thread that
is, not the worker thread) :o)
Tom
"David Ching" <dc@remove-this.dcsoft.com> wrote in message
news:BZREj.1446$p24.306@nlpi061.nbdc.sbc.com...
"Aditya" <adityaborah@gmail.com> wrote in message
news:e77e8622-9295-45c2-b0ae-1b8d3c9ded2e@i12g2000prf.googlegroups.com...
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
Perhaps you need to show the exact code you're talking about. It's not
clear what you mean by "UI operation from other threads." Only the
primary thread should do UI operations. Anything that takes a long time
should be on another thread. And the primary thread should not be looping
or sleeping while the other thread is working, or else it won't process
messages and hang.
-- David