How to: Purge Queue Contents
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
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.
Expand the Message Queues node.
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.
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();
System.Messaging.MessageQueue MessageQueue1 = new System.Messaging.MessageQueue(); MessageQueue1.set_Path("myMachine\\MyQueue"); MessageQueue1.Purge();
This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Windows Operating System > Message Queues. For more information, see How to: Insert Snippets Into Your Code (Visual Basic).