Subj : Re: Win32 PostMessage Question To : comp.programming.threads From : robertwessel2 Date : Wed Jul 06 2005 03:11 pm Cool Guy wrote: > From a *worker thread*, I'm posting messages to the *GUI thread* of my > application (via PostMessage). > > If I send two such messages in a row (both from the same worker thread), is > the first one *guaranteed* to be in front of the second one in the message > queue that receives these messages? > > e.g.: > > (in worker thread) > { > PostMessage(...); // post *first* message to GUI thread > PostMessage(...); // post *second* message to GUI thread > } > > Is the first message here guaranteed to appear ahead of the second message > in the receiving message queue? > > I assume so but I'm asking just to make sure. Short answer: yes. Long answer: First, since you're not checking the return codes from the posts, the first message might silently not enter the target's message queue at all. Second, there are certain system generated messages (WM_TIMER, WM_PAINT, and a few others), that have special behavior, and can do some quite odd things if you actually try to post them yourself (which you're not supposed to). Third, the target application has some control over how messages are removed from the queue, which doesn't impact the order in which they're put into the queue, but can certainly impact the order in which the receiving application sees them. Finally, an application doesn't necessarily have to finish processing one message before retrieving another (if there's an embedded message pump somewhere), which doesn't change the order, but does create overlap in the sense that the second message can be processed after the processing of the first message starts but before it completes. But if you stick with user messages, or messages you're normally allowed to send, and assume typical behaviors for the target application, and you don't overflow the target queues, they'll arrive in order. .