0
votes

My understanding of the size limit on the message queue in a MFC thread comes from the explanation on PostThreadMessage page of MSDN.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms644946%28v=vs.85%29.aspx

As stated, the limit by default is 10000 messages. I am trying to understand exactly what this limit is. I see it being one of two thing.

Scenario A

I have a GUI that is handling messages. The rate at which the messages are being placed in the queue is greater than that at which these messages are being pulled off the queue and handled. In this case messages accumulate, eventually there are 10000 messages on the queue, another message tries to join the queue, but it then fails.

Scenario B

I have a GUI that is handling messages. The rate at which message are being placed in the queue is less that then rate at which these messages are being pulled of the queue and handled. Messages do no accumulate on the queue. But after my queue has seen 10000 messages, it is rendered useless, so effectively, my message queue has a limited operational life.

The more I think about it, the answer should be Scenario A... but stranger things have happened..

1
This question is confusing to me. It is unclear what kind of messages do you mean - MFC is mainly a GUI library, i.e. mainly GUI messages are sent. MFC isn't aimed at messages sent among threads. See PostMessage() function. - Al Kepp
What?! How does your comment even relate to my question? For starters, what is to say that my question is not referring to a GUI based application? Maybe the question is confusing, but so is your comment. - tuskcode
Actually, your Scenario B is a bit confusing... From the linked article: GetLastError returns ERROR_NOT_ENOUGH_QUOTA when the message limit is hit. So, every attempt to send/post message when the queue is full fails, that's all. - Alex F
(@AlKepp)PostThreadMessage is used in the event when you have a message queue in a CWinThread. Why am I using a message map in a CWinThread? Because it suits my application. I wish my thread to do some work, in the mean time some other threads may wish to send it updates, I don't want these updates to interrupt the work I am doing, so I have these update placed in a queue to be serviced next time the thread has some free time... hence why I have a message queue. My question was not, "Should I use a messages in my CWinThread implementation.." - tuskcode
So maybe it isn't B, I'm leaning away from B.. mainly because it seems a little illogical in a programming sense.. - tuskcode

1 Answers

1
votes

From the linked article: GetLastError returns ERROR_NOT_ENOUGH_QUOTA when the message limit is hit. So, every attempt to send/post message when the queue is full fails, that's all.

Generally, destination thread handles the messages and removes them from the queue. PeekMessage with PM_NOREMOVE flag allows to handle the message without removing it. For reference, PeekMessage function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms644943%28v=vs.85%29.aspx