Re: SendMessage (in secondary thread) freezes application GUI thread?



SendMessage blocks until the window that you've sent the message to is done
processing it (that's why PostMessage exists). I would guess that you have
a deadlock there.

Thread A calls SendMessage while holding an exclusive lock on something.
This might be a mutex, a spin lock, almost any object designed to prevent a
second thread from accessing some resource.

Thread B calls GetMessage() and begins processing it, but, because there's a
lock on the object, it goes into a wait state until the lock is released.

Obviously, the lock is never going to be released, since SendMessage doesn't
return until the message processing is complete. It's possible that the
'lock' is something which is automatically released by the OS after some
period of time or there might be a long time-out on the wait.

Paul T.

"skyapie" <skyapie@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9416563C-37F0-46DC-9515-949477AF299C@xxxxxxxxxxxxxxxx
Asking this question in a simpler way,

What could cause SendMessage to get stuck, causing the receipient hWnd to
not get it's message?

Thanks
skyapie

"skyapie" wrote:

Hi,

Has anyone ever come across the same problem and found a solution to the
following?

I have 1 background thread that periodically calls "SendMessage". The
SendMessage sends a message to my main thread (which also handles the
GUI),
saying "start processing!" The main thread then starts processing, and
returns to the secondary thread when it has completed the processing it
needs
to do and updated the GUI.

This works fine most of the time, but randomly the GUI on my application
will freeze (I can tell because there's a clock on the screen that
suddenly
just disappears... and this clock changes the time it displays by doing a
time(¤tTime), and updating the display on every OnDraw function call.
(Received when WM_PAINT gets processed).

The odd thing is, the application un-freeze (come back to life) after 1/2
hour to 1 hour... And all my logging statements always stop at the same
point
when my application freezes. I log a statement before SendMessage, and at
the
point where the message handling function gets entered. My log shows that
the
SendMessage statement gets executed, but the message handling function in
the
active view doesn't get entered.

Can anyone help please?? I have no clue how to debug into SendMessage,
let
alone reproduce this consistently. The freezing seems to happen randomly
at
the same point in the code. (IE: it works most of the time.... )

Much appreciated
skyapie


.



Relevant Pages