Share via


How to: Purge Queue Contents

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

You can use the Purge method to clear the contents of any queue to which you have access rights in the Message Queuing system. For example, suppose you use a journal queue on your local Message Queuing client to record copies of all messages you send out. When that journal reaches its maximum size, you might use the Purge method to clear out the items you no longer need.

Note

Messages stored in journal and dead-letter queues count against the quota for the computer where the queue resides. When the quota is reached, these queues stop accepting new messages. It is important to periodically clear messages that are no longer needed from journal and dead-letter queues if you are using these in your application.

You must have Receive rights in Message Queuing to delete the contents of a queue. When you purge a queue, all of the messages it contains are discarded without being sent. You can purge a queue's contents from code or from Server Explorer.

To purge a queue's contents from Server Explorer

  1. Open Server Explorer, and then expand the node for the server on which the queue you want to purge resides.

    Tip

    If you do not see the server you want listed in the Servers node, right-click Servers, click Add Server, enter the name of your server, and then click OK.

  2. Expand the Message Queues node.

  3. Expand the queue from which you want to delete messages. You will see one or more nodes for the queue's messages and its associated journal messages.

  4. Right-click the message node you want to clear, and then click Clear Messages.

To purge a queue's contents programmatically

  • Use the Purge method to clear the contents of the appropriate queue. Your code should look something like this:

    Dim MessageQueue1 As New System.Messaging.MessageQueue()
    MessageQueue1.Path = ".\MyQueue"
    MessageQueue1.Purge()
    
            System.Messaging.MessageQueue MessageQueue1 =
               new System.Messaging.MessageQueue();
            MessageQueue1.Path = @".\MyQueue";
            MessageQueue1.Purge();
    

See Also

Tasks

How to: Create Queues

Other Resources

Creating, Deleting, and Administering Queues