Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. 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?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
6 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    namaskaaram
    wrote on last edited by
    #1

    how do i know the number of messages left unprocessed in a message queue?

    P 1 Reply Last reply
    0
    • N namaskaaram

      how do i know the number of messages left unprocessed in a message queue?

      P Offline
      P Offline
      Patrick G
      wrote on last edited by
      #2

      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.

      N 1 Reply Last reply
      0
      • P Patrick G

        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.

        N Offline
        N Offline
        namaskaaram
        wrote on last edited by
        #3

        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.

        P D M 3 Replies Last reply
        0
        • N namaskaaram

          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.

          P Offline
          P Offline
          Patrick G
          wrote on last edited by
          #4

          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 to EnableNotification() 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 the PeekNext() 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.

          1 Reply Last reply
          0
          • N namaskaaram

            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.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • N namaskaaram

              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.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              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:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups