Deletes a queue backend resource identified by the given path.
[Visual Basic] Public Shared Sub Delete( _ ByVal path As String _ ) [C#] public static void Delete( string path ); [C++] public: static void Delete( String* path ); [JScript] public static function Delete( path : String );
Exception Type | Condition |
---|---|
ArgumentException | The path parameter is a null reference (in Visual Basic Nothing) or an empty string. |
MessageQueueException | The syntax for the path parameter is invalid. |
MessageQueueException | The attempt to access the queue's Formatter property while deleting the queue generated an exception specified by the given status message. |
You should close the queue before deleting it. If you send messages to a deleted queue, they will either throw exceptions or be sent to the Deadletter queue.
The syntax for the path parameter depends on the type of queue it references. The following table shows the syntax you should use for a queue of a specified type.
Queue Type | Syntax |
---|---|
Public Queue | MachineName\QueueName |
Private Queue | MachineName\Private$\QueueName |
You can also use the FormatName or Label of a Message Queuing object to describe the queue path. The following table shows the proper syntax for each type of reference.
Reference | Syntax |
---|---|
Format Name | FormatName:[format name] |
Label | Label:[label] |
The following example closes and deletes a Message Queuing backend resource. It assumes that a queue path has been passed in from the calling application, and that the path refers to a queue on the local computer.
As recommended, the queue is closed before there is an attempt to delete it. This ensures that further messages will not be sent to it before the backend resource is removed from Message Queuing.
This procedure assumes you can delete queues from the local machine.
[Visual Basic]
Private Sub TerminateQueue(ByVal queuePath As String) 'Define and instantiate a new MessageQueue. Dim MessageQueue1 As MessageQueue MessageQueue1 = New MessageQueue(queuePath) 'Close the message queue so it stops receiving messages. MessageQueue1.Close() 'Delete the queue. This is a static method. MessageQueue.Delete(queuePath) End Sub
MessageQueue Class | MessageQueue Members | System.Messaging Namespace | Create | Close | Path