This is my 2nd question here on SO, hope I didn't screw up anything!
The question is theoretical because my implementation seems working perfectly, I just want to be sure it's ok.
I create mulitple threads that as part of their work PostMessage() to the main thread. The main thread then waits for all the threads to terminate. After all threads terminated the main thread calls Application.ProcessMessages. So the question is after this call is it sure that all the messages are received?
If PostMessage()
returns nonzero, it is guaranteed that the message has been put into the message queue of the thread that owns the window being posted to.
Application.ProcessMessages()
is a blocking function. It does not exit until the message queue of the calling thread has been completely cleared of pending messages.
Now, whether a posted message actually reaches the message procedure of the window it is posted to is another matter. There are factors that can prevent that. Bad message queue filtering. The window being destroyed before the message is removed from the queue. Etc. However, given the example you describe, it is unlikely any of those would occur.
So yes, once all of the threads have fully terminated, and a subsequent call to Application.ProcessMessages()
has exited, you are guaranteed to not receive any further messages from the threads.