Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How robust are windows messages?

Tags:

c++

winapi

If i queue a message with PostMessage (and it return true) can i be certain that eventually the window will process the message unless some catastrophic event happen?(something which will crash the program anyway)

like image 806
Lishi Avatar asked Mar 16 '11 13:03

Lishi


2 Answers

Once posted messages don't disappear from the queue.

One of our products is a Windows service that uses Windows messages to communicate between threads and it relies on them heavily. So far the only problem we've seen is that if you post them too fast the queue just fills and doesn't accept more messages until someone starts draining the queue.

like image 84
sharptooth Avatar answered Nov 08 '22 22:11

sharptooth


You can be certain that the message will be in the queue if the call to PostMessage() succeeds.

PostMessage() will fail if the receiving queue is full. MSDN says:

There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the following registry key.

You can't be certain that posted messages will ever be processed because it's up to the other app to decide whether or not to pump its message queue.

This is being a little pedantic because in reality an app that doesn't ever pump its queues never gets run by anyone through a process of natural selection!

like image 39
David Heffernan Avatar answered Nov 08 '22 22:11

David Heffernan