The Delete method deletes an existing queue (it does not delete the MSMQQueueInfo object used to create the queue).
object.Delete
Syntax Element | Description |
object | The queue information (MSMQQueueInfo) object that defines the queue. |
For information on return codes, see MSMQ Error and Information Codes.
Deleting the queue does not delete the MSMQQueueInfo object, only the existing queue. You can still create a new queue based on the current properties of the MSMQQueueInfo object.
When deleting public queues, some clients may still see the queue registered in MQIS after the queue was deleted. Changes to MQIS (such as deleting a public queue) are propagated from site to site, which can cause delays in viewing the most current information. Consequently, clients in some sites may still try to send messages to the queue, even though it was deleted. Propagation delays, including communication network delays such as down links, are controlled by the MSMQ Administrator.
This example assumes at least one queue whose label is "Test Queue" already exist. It runs a query for the test queues, asking if you want to delete each queue it finds.
To try this example using Microsoft Visual Basic (version 5.0), paste the code into the Code window of a form, and then run the example and click the form.
Dim query As New MSMQQuery Dim qinfos As MSMQQueueInfos Dim qinfo As MSMQQueueInfo Dim Response As String Private Sub Form_Click() Set qinfos = query.LookupQueue(Label:="Test Queue") qinfos.Reset Set qinfo = qinfos.Next While Not qinfo Is Nothing Response = MsgBox("Delete queue: " + qinfo.Label, vbYesNo) If Response = vbYes Then qinfo.Delete End If Set qinfo = qinfos.Next Wend End Sub
Label, LookupQueue, MSMQQuery, MSMQQueueInfos, MSMQQueueInfo, Next, Reset