Re: a *working* PostThreadMessage() implementation...?
On Thu, 2 Oct 2008 09:40:01 -0700 (PDT), ".rhavin grobert" <clqrq@yahoo.de>
wrote:
On 2 Okt., 18:18, "Doug Harrison [MVP]" <d...@mvps.org> wrote:
On Thu, 2 Oct 2008 05:26:38 -0700 (PDT), ".rhavin grobert" <cl...@yahoo.de>
wrote:
On 2 Okt., 00:02, "Doug Harrison [MVP]" <d...@mvps.org> wrote:
I meant it would be better than trying to roll one's own message queue to
work around the PostThreadMessage issues. In order for PTM to work right,
all message loops have to account for it, which could be a problem down the
road if you add a secondary message loop for some reason.
?
there are only two acceptable scenarios:
1: Message IS delivered to the treads message queue and WILL appear in
the threads own message loop
2: Message cant be delivered and the posting-Fn return an error.
Then you should be happy with PostThreadMessage, because it satisfies those
two criteria.
in my experience it doesnt ;-)
That's because you're not interpreting your criteria literally. The
function does what you described, but not what you want. There's a
difference.
Seriously. The problem occurs when one or more message loops
the thread runs fail to handle messages posted by PostThreadMessage.
i've experienced enough cases where the message doesnt even appear.
Appear where? From (1), in the "message queue", or the "threads own message
loop"? I'm rather certain that the message does appear in the "message
queue", and I believe you're not understanding that there really is no such
thing as the "threads own message loop". Any thread can have any number of
message loops, and Windows runs some of its own during certain UI
operations. Thus, the message loop that is currently running IS the
"threads own message loop". The problem with PostThreadMessage is that a
message loop has to be specially constructed to handle "thread messages",
and those secondary message loops inside the OS don't (and can't) handle
"thread messages" and will thus discard them. That's the reason for KB
articles like this one:
PRB: PostThreadMessage Messages Lost When Posted to UI Thread
http://support.microsoft.com/kb/183116
if you use PostMessage to a (hidden) window, any message loop that uses
DispatchMessage will handle things fine. In order to run into a problem
with PostMessage, the message loop would have to eat a message it knows
nothing about, which would be a rare bug.
my current implementation looks like this and im currently testing it
(seems to run):
<snip>
I didn't vet that code beyond noting that you're making things pretty
difficult for yourself. :)
--
Doug Harrison
Visual C++ MVP