Share via


Purging a Queue Asynchronously (COM)

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

When asynchronously retrieving messages from a queue, you must enable notification to read the first message, then re-enable notification after each message is read. The combination of how notification is enabled and how the message is retrieved determines when the arrived event is fired.

To asynchronously purge the messages from the queue, notification is enabled using the default cursor (Cursor = MQMSG_FIRST) setting. This setting causes an arrived event to be fired whenever there is a message in the first message location of the queue.

To purge the queue asynchronously

  1. Declare the objects needed to retrieve a message.

  2. Obtain a valid MSMQQueueInfo object.

    The MSMQQueueInfo object in the following code example is obtained by creating a new queue if an existing queue does not exist.

  3. Call MSMQQueueInfo.Open to open queue with receive access.

  4. Call MSMQQueue.EnableNotification to start notification.

    (The Cursor parameter for EnableNotification is not specified in the following code example.)

  5. Write Arrived event handler.

    The event handler in the following code example calls MSMQQueue.Receive to remove the first message in the queue and then calls MSMQQueue.EnableNotification to re-enable notification without specifying its Cursor parameter.

  6. Write Arrived Error event handler.

See Also

Concepts

MSMQ COM Support
Using the COM Components
MSMQ Security

Other Resources

Message Queuing