Suspend MessageQueue.BeginReceive Operation...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Richmeier

    Suspend MessageQueue.BeginReceive Operation...

    I have been unable to locate an answer for this question because (1) it is
    late in the day and my eyes are tired of looking at code and documentation,
    (2) I am new to this area of the .NET framework, or (3) a combination of (1)
    and (2).

    I am looking at using messaging in an application I am working on. I have
    been reading the documentation about messaging and have been able to
    understand just about everything that I have read so far. I don't see it as
    being a requirement, but how do you suspend an asynchronous receive operation
    on a message queue? Once the BeginReceive method is called, I would like to
    stop the MessageQueue object from listening for new messages.

    Thank you,

    Jason Richmeier
  • Luke Zhang [MSFT]

    #2
    RE: Suspend MessageQueue.Be ginReceive Operation...

    The MessageQueue class is a wrapper around Message Queuing, you can use
    Create(String), Delete, and Purge methods to manage queues on the server,
    but you cannot block the MessageQueue to recieve new messages. Also, I
    didn't think there is any reason to block new message when BeginReceive is
    called. What is your opinion?


    Luke Zhang
    Microsoft Online Community Support

    =============== =============== =============== =====
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    =============== =============== =============== =====

    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Comment

    • Jason Richmeier

      #3
      RE: Suspend MessageQueue.Be ginReceive Operation...

      I am not so much interested in blocking new messages as I am suspending or
      cancelling the receipt of new messages.

      For example, say I have a windows service that monitors for new messages and
      this service repeatedly calls the BeginReceive method to watch for new
      messages. When the service is paused, I don't want to monitor for new
      messages and when the service is resumed, I once again want to monitor for
      new messages.

      I have tried to figure out a way to cancel the asynchronous receive
      operation when the service is paused but I haven't found anything yet. The
      best I have come up with is to use a shared flag of some sort and update it
      when the service is paused and resumed. Then, I would use a BeginPeek
      instead of a BeginReceive (since the latter removes messages from the queue).
      When a new message became available, I would check the value of the flag to
      see if the service was currently running and receive the message if it was.
      This seems like a rather odd way of doing it but it is the best I have been
      able to come up with so far.

      Any suggestions?

      Thank you,

      Jason Richmeier

      "Luke Zhang [MSFT]" wrote:
      [color=blue]
      > The MessageQueue class is a wrapper around Message Queuing, you can use
      > Create(String), Delete, and Purge methods to manage queues on the server,
      > but you cannot block the MessageQueue to recieve new messages. Also, I
      > didn't think there is any reason to block new message when BeginReceive is
      > called. What is your opinion?
      >
      >
      > Luke Zhang
      > Microsoft Online Community Support
      >
      > =============== =============== =============== =====
      > When responding to posts, please "Reply to Group" via your newsreader so
      > that others may learn and benefit from your issue.
      > =============== =============== =============== =====
      >
      > (This posting is provided "AS IS", with no warranties, and confers no
      > rights.)
      >
      >[/color]

      Comment

      • Luke Zhang [MSFT]

        #4
        RE: Suspend MessageQueue.Be ginReceive Operation...

        When the service is paused, you may simply call the MessageQueue's Close
        method to close it direclty. When the service is resume or restart, create
        a new MessageQueue object to receive the message. Can this work for your
        system?

        Luke Zhang
        Microsoft Online Community Support

        =============== =============== =============== =====
        When responding to posts, please "Reply to Group" via your newsreader so
        that others may learn and benefit from your issue.
        =============== =============== =============== =====

        (This posting is provided "AS IS", with no warranties, and confers no
        rights.)

        Comment

        • Jason Richmeier

          #5
          RE: Suspend MessageQueue.Be ginReceive Operation...

          I believe I understand your statement correctly so, unless I am doing
          something wrong in my code, this method does not work.

          In the OnStart method in my code, I create a MessageQueue object (with class
          scope) and set its properties as necessary. Also in this method, I call the
          BeginReceive method of this MessageQueue object.

          In the OnPause method in my code, I call the Close method of the
          MessageQueue object that was created in the OnStart method.

          In the OnContinue method in my code, I reinitialize the MessageQueue object
          (the same as what is done in the OnStart method).

          For now, when a message is received in the message queue, I write an entry
          to the event log. If the service is running and I send a message to the
          queue, an entry is made in the event log. If I pause the service and send
          another message to the queue, another entry is made in the event log.
          However, the message is not removed from the queue. Once I resume the
          service, another entry is made in the event log and the message is removed
          from the queue. So, if I send one or more messages to the queue after
          pausing the service, an extra entry is made in the event log.

          I read a document that lead me to believe that in order to prohibit this
          behavior, the property EnableConnectio nCache should be set to false. I did
          this but the described behavior continues.

          Jason Richmeier

          "Luke Zhang [MSFT]" wrote:
          [color=blue]
          > When the service is paused, you may simply call the MessageQueue's Close
          > method to close it direclty. When the service is resume or restart, create
          > a new MessageQueue object to receive the message. Can this work for your
          > system?
          >
          > Luke Zhang
          > Microsoft Online Community Support
          >
          > =============== =============== =============== =====
          > When responding to posts, please "Reply to Group" via your newsreader so
          > that others may learn and benefit from your issue.
          > =============== =============== =============== =====
          >
          > (This posting is provided "AS IS", with no warranties, and confers no
          > rights.)
          >
          >[/color]

          Comment

          • Luke Zhang [MSFT]

            #6
            RE: Suspend MessageQueue.Be ginReceive Operation...

            Hello Jason,

            Thank you the information, However, I am a little confused by what you
            said, how did you write an entry to the event log, in the windows service
            application or external application? When the service is paused, did you
            send messages to the queue, from external application?

            Thanks,

            Luke Zhang
            Microsoft Online Community Support

            =============== =============== =============== =====
            When responding to posts, please "Reply to Group" via your newsreader so
            that others may learn and benefit from your issue.
            =============== =============== =============== =====

            (This posting is provided "AS IS", with no warranties, and confers no
            rights.)

            Comment

            Working...