Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetWindowText hang

541 views
Skip to first unread message

Paul Roder

unread,
Oct 23, 2001, 12:31:09 PM10/23/01
to
I have a multithreaded program where one thread is
writing information to a window created in another
thread. This works properly until the first thread
calls a certain WaitForSingleObject. At this point,
calls to CWnd->SetWindowText hang. In fact, even if I
timeout from the wait in a loop, the other thread
remains hung. I don't understand this because after
I come out of the wait, shouldn't the windows handler
process the message? It is doing that earlier on
under the same circumstances. Anybody have any
suggestions?

Jay Nabonne

unread,
Oct 23, 2001, 12:40:53 PM10/23/01
to

"Paul Roder" <paul_...@hp.com> wrote in message
news:1f9d01c15be0$1f59b820$19ef2ecf@tkmsftngxa01...

I don't know if this applies to you, but it sounds like it... SetWindowText
eventually results in a WM_SETTEXT message being sent to the window. If the
SendMessage is coming from a different thread, the thread that created the
window (the one receiving the message) must be processing messages.
Otherwise, the SetWindowText/SendMessage blocks.

I'm a little unclear on which thread is doing the waiting, but if it's the
one that created the window, it makes sense - any message sent to the window
from a different thread will be blocked. What you probably want to do
instead of WaitForSingleObject is to use MsgWaitForMultipleObjects (with
your single object) so you can process messages while you wait. I can
elaborate on how to do that if you'd like...

--
Jay Nabonne

William DePalo [MVP]

unread,
Oct 23, 2001, 12:52:55 PM10/23/01
to
"Paul Roder" <paul_...@hp.com> wrote in message
news:1f9d01c15be0$1f59b820$19ef2ecf@tkmsftngxa01...

It wouldn't shock me if SetWindowText() were to send a WM_SETTEXT message to
the thread that owns the window in question. If that is so, the receiver
_must_ be in a position to pump messages. Which is to say that threads that
own windows are never to block for very long. When they do, applications
that send them messages hang.

Regards,
Will


Simon Cooke

unread,
Oct 24, 2001, 7:17:08 AM10/24/01
to

"Jay Nabonne" <j...@rightagain.com> wrote in message
news:#qHc9F#WBHA.2040@tkmsftngp05...

Yep, it's the one that created the window that is doing the waiting;
SendMessage will wait until the message pump does its thing again.

Another possibility (one I've not researched) is that SendMessage waits for
this to occur *or* the thread entering an alertable wait state. It'd be
interesting to try doing a WaitforSingleObjectEx call with alerts turned on
(and appropriate looping of the Wait call), to see if the SendMessage can
use an APC call to get its stuff done :)

Si


0 new messages