I created a multichilded application. The application windows (W[n]: TMyWindows) are all the same and all have an private object class instance associated with them (E: TMyObject). The child windows generate through this objects some messages. I have created in the main application two threads which process these messages depending on the content of the messages. For example lets have the following asynchronous calls:
W[1].E.Service(thread1service)
W[2].E.Service(thread2service)
the TMyObject.Service(servicetype) is
case servicetype of
thread1service: PostThreadMessage(thread1id,...);
thread2service: PostThreadMessage(thread2id,...);
end;
Now, in the Execute Method of each thread i have something like that:
while not terminated do
begin
...
if peekmessage(msg,0,thread1message_1,thread1message_n,pm_remove) then
process message
do other things;
end
All goes fine exept that the second thread doesn't receive any messages. Do you have any idea why?
I would check to make sure that the range you are supplying to
PeekMessage()is valid. Try putting zeros in instead to receive all messages, like this:If that doesn't work, I would check the result of the
PostThreadMessage()function... It may be that the thread hasn't calledPeekMessage()yet, that's what prompts windows to create the message queue for you.As stated in this article (under "Remarks"), you can either check the result of the call to
PostThreadMessage(), andSleep()if it fails, or use an event to signal to the main thread that the child thread is ready to receive messages.HTH,
N@