Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Nov : How to make PostMessage *more* asynchronous
| Subject: | How to make PostMessage *more* asynchronous |
| Posted by: | "Ian Boyd" (ian.borlandnews0..@avatopia.com) |
| Date: | Thu, 16 Nov 2006 14:17:49 |
i have a thread that posts messages to it's parent
OutputDebugString('>>> '+IntToStr(GetTickCount)+' Posting message to
parent');
PostMessage(FParentHandle, WM_MyMessage, 0, 0);
OutputDebugString('<<< '+IntToStr(GetTickCount)+' Done posting message to
parent');
And then in the parent's WindowProc:
case Message.Msg of
WM_MyMessage:
begin
OutputDebugStr(' >>> '+IntToStr(GetTickCount)+' Processing
MyMessage');
ProcessSomething;
OutputDebugStr(' <<< '+IntToStr(GetTickCount)+' Done
processing MyMessage');
end;
...
So, of course the debug log shows:
ODS: >>> 83975209 Posting message to parent
ODS: >>> 83975209 Processing MyMessage
ODS: <<< 83975219 Done processing MyMessage
ODS: <<< 83975229 Done posting message to parent
ODS: >>> 83975410 Posting message to parent
ODS: >>> 83975420 Processing MyMessage
ODS: <<< 83975420 Done processing MyMessage
ODS: <<< 83975430 Done posting message to parent
ODS: >>> 83975610 Posting message to parent
ODS: >>> 83975610 Processing MyMessage
ODS: <<< 83975620 Done processing MyMessage
ODS: <<< 83975620 Done posting message to parent
ODS: >>> 83975800 Posting message to parent
ODS: >>> 83975810 Processing MyMessage
ODS: <<< 83975820 Done processing MyMessage
ODS: <<< 83975830 Done posting message to parent
ODS: >>> 83976011 Posting message to parent
ODS: >>> 83976011 Processing MyMessage
ODS: <<< 83976021 Done processing MyMessage
ODS: <<< 83976021 Done posting message to parent
ODS: >>> 83976201 Posting message to parent
ODS: >>> 83976211 Processing MyMessage
ODS: <<< 83976221 Done processing MyMessage
ODS: <<< 83976231 Done posting message to parent
ODS: >>> 83976411 Posting message to parent
ODS: >>> 83976421 Processing MyMessage
ODS: <<< 83976421 Done processing MyMessage
ODS: <<< 83976431 Done posting message to parent
ODS: >>> 83976611 Posting message to parent
ODS: >>> 83976611 Processing MyMessage
ODS: <<< 83976621 Done processing MyMessage
ODS: <<< 83976621 Done posting message to parent
So, my call to PostMessage is getting hung up while the receiver processes
the message. i figured this out after instrumenting everything, and finding
the largest bottleneck in the thread was a call to PostMessage()
So, i'm looking for techniques to make a call to PostMessage more
asynchronous. i'm thinking of something like creating a 3rd thread who's job
is to solely to Post the message, and rather than calling
PostMessage
i'd call
MessagePosterThread.Resume;
who then is sitting in the loop:
while not Terminated do
begin
Sleep;
PostMessage(FParentHandle, WM_MyMessage, 0, 0);
end;
Of course now i'd have to ensure that i wake the thread properly when i want
it to go away; and all kinds of other pessimistic cases. Anyone have any
other ideas of how to make either
a) PostMessage asynchronous
c) a call to PostMessage not tie up the thread
d) send asynchronous messages to another window which that window will
receive when it processes it's message loop.