Deletes all the messages contained in the queue.
[Visual Basic] Overridable Public Sub Purge() [C#] public virtual void Purge(); [C++] public: virtual void Purge(); [JScript] public function Purge();
The following example uses the Peek and Receive methods on a queue. A Message object is instantiated to refer to the first message in the queue. If the first message is an application-defined marker, the queue is purged. Otherwise, the first message is read and removed.
This procedure assumes that the queue "myQueue" exists on the computer "myComputer". It also assumes that the message body "Purge the queue" is used to indicate that the queue should be purged.
[Visual Basic]
Private Sub PeekQueue() 'Define a Message. Dim msg As System.Messaging.Message 'Define a string to hold the contents of the message body Dim msgBody As String 'Define a new MessageQueue. Dim messageQueue1 As MessageQueue 'Associate the MessageQueue with the given queue. messageQueue1 = New MessageQueue("myComputer\myQueue") 'Read without removing (peek) the first message in the queue. msg = messageQueue1.Peek 'If the message body indicates a specific marker, purge the queue. If msg.BodyStream.ToString = "Purge the queue." Then messageQueue1.Purge() Else 'Otherwise, remove the top message from the queue (receive it). msg = MessageQueue1.Receive End If End Sub
MessageQueue Class | MessageQueue Members | System.Messaging Namespace