PRB: PostThreadMessage Messages Lost When Posted to UI Thread (183116)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0
This article was previously published under Q183116 SYMPTOMS
Messages sent to a UI thread through PostThreadMessage are lost if the
messages are posted while the user is manipulating a window owned by the
thread. Messages might be lost if they are sent while the user moves or
resizes the window or if the window is a modal dialog box.
CAUSE
When an UI thread is involved in modal behavior, the thread pumps messages
in a message loop internal to the modal system rather than in the thread's
main message loop. Messages that are posted to a window can still be
dispatched to the window procedure of the target window, because the
messages are associated with a window. However, thread messages need to be
handled directly by the message loop, because they cannot be automatically
dispatched elsewhere. Since the secondary message loop does not know about
the thread message, it will be dropped.
RESOLUTION
Rather than using PostThreadMessage to post messages to a UI thread, use
PostMessage to post messages to a window owned by that thread. Since
messages directed to a window can be dispatched by a secondary message
loop, the messages is still handled properly, even when the thread is not
running in its primary message loop.
To use this method, the thread must create a window that lives throughout
the period that it must receive messages, and the application sending the
messages must have a handle to that window available.
STATUS
This behavior is by design.
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbprb kbWndw KB183116 |
---|
|