|Subject:||Re: Messages sent with PostMessage getting lost|
|Posted by:||Jeremy Darling (jdarli…@eonclash.com)|
|Date:||Sun, 16 Oct 2005|
By posting do you mean using the Windows message queue or your own
specialized messaging queue? If you are using the windows one then I
believe that messages can fall off the queue and are cleaned up by the OS.
Thou I can't refer you to an article about this, as is my usual, I seem to
remember it in the back of my mind.
Either way I'm sure that Remy (Gambit) will correct me here if I'm wrong.
Personally I'd try implementing a Producer/Consumer algorythm instead of
using a standard message queue. Its typically more flexiable, and you can
set it up so that when x messages accrue into the system it will
automatically call sleep or processmessages to allow the main VCL thread
time to process the stack.
"Ross McMillan" <email@example.com> wrote in message
> I'm writing an Indy app that send emails in parallel from threads. I
> wanted the threads to report back progress, bytes sent, etc regularly and
> I had done this by accessing strings in the thread from the VCL loop.
> Now, after being wrapped over the knuckles by Martin James (and quite
> rightly too I now realise) I am in the process of reporting back progress
> by PostMessage.
> Just to satisfy my curiousity I wrote a test program that started a thread
> and furiously assigned to a string from within the thread, and then
> checked the string from the main loop (via Application.OnIdle). As
> expected, every so often (but not very often), the string as seen by the
> main loop is not what it should be. Also, and very much less often, I get
> an AV. Whatever, confirmation that it's not a good idea.
> Next step was to try posting the string back. I create a record for the
> string with New in the thread and pass it's address as a message parameter
> and post it off.
> In the main thread message handler I grab the string, check it, and
> release the memory that was used to transport it back. As expected, it
> runs without errors in the received string.
> Just to really push things, I didn't send off one message in the thread -
> I send off 1000 at a time and follow with a sleep so that the main thread
> gets a chance to handle the messages. I keep track of messages posted and
> messages delivered and find that over time, I lose some of them.
> Presumably the storage I create to transport the string gets lost also -
> i.e. I leak memory.
> What's going on here? Can we not assume that all messages posted make it
> to the handler?
Messages sent with PostMessage getting lost posted by Ross McMillan on Mon, 17 Oct 2005