Share via


Purging a Queue Asynchronously (COM) (Windows Embedded CE 6.0)

1/6/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

Purging Messages in a Queue (COM)
MSMQ COM Support
Using the COM Components
MSMQ Security

Other Resources

Message Queuing