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 a public queue, some clients may still see the queue registered in Active Directory after the queue was deleted. Changes to Active Directory (such as deleting a public queue) are propagated from domain controller to domain controller, which can cause delays in the availability of new information. Consequently, clients using a specific domain controller 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 exists. 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, 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
Windows NT: Requires version 4.0 SP3 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in mqoai.h.
Import Library: Use mqoa.lib.
Unicode: Defined only as Unicode.
Label, LookupQueue, MSMQQuery, MSMQQueueInfos, MSMQQueueInfo, Next, Reset