how do i know the number of messages left unprocessed in a message queue?
-
how do i know the number of messages left unprocessed in a message queue?
-
how do i know the number of messages left unprocessed in a message queue?
This depends on the implementation of the message queue. If you have a message queue class, perhaps there is a getQueueLength() method? Or, if it's implemented similarly to a C string, perhaps there is a terminator at the end of an array? There is always a brute force approach, iterate through every element and count it, but this is not what I would call a good solution. On that note, to give you a good answer, you need to post more information about what you're doing.
-
This depends on the implementation of the message queue. If you have a message queue class, perhaps there is a getQueueLength() method? Or, if it's implemented similarly to a C string, perhaps there is a terminator at the end of an array? There is always a brute force approach, iterate through every element and count it, but this is not what I would call a good solution. On that note, to give you a good answer, you need to post more information about what you're doing.
I am just reusing the message queue provided by windows. I have a message handler thread which at some point need to flush out the message queue. I didnt seem to find any win apis for the same.
-
I am just reusing the message queue provided by windows. I have a message handler thread which at some point need to flush out the message queue. I didnt seem to find any win apis for the same.
I must admit, I havn't used the Microsoft queue, but I have used my own queues as well as queues written for POSIX in Linux. Typically, I've found that there is a length() method on the queue class. In the searches that I just ran I can't say that I've found this to be the case for Microsoft, but I did notice a few methods that could be used to cobble something up with from here: http://msdn.microsoft.com/en-us/library/ms699810(VS.85).aspx[^]. A few ideas that came to mind as I was reading this (unfortunately none of them are as elegant as a
getLength()
method). One idea that could work is toEnableNotification()
and then to have your own counter that increments when a message is received and decrements when a message is used. Another is to use repeated calls to thePeekNext()
method in a loop, counting the number of elements in the queue as you go. Sorry I couldn't be more insightful for you. I hope that what I've found helps you set up an algorithm to get your program working the way you want it to. -
I am just reusing the message queue provided by windows. I have a message handler thread which at some point need to flush out the message queue. I didnt seem to find any win apis for the same.
Why would you think that Windows would need help in managing its message queue?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I am just reusing the message queue provided by windows. I have a message handler thread which at some point need to flush out the message queue. I didnt seem to find any win apis for the same.
namaskaaram wrote:
I have a message handler thread which at some point need to flush out the message queue.
Call PeekMessage(...PM_REMOVE) in a loop until it returns 0. But really, why? Where are the messages coming from and why do you have no control over this? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: