MessageQueue.Delete Method
Deletes a queue on a Message Queuing server.
[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 );
Parameters
- path
- The location of the queue to be deleted.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentException | The path parameter is a null reference (Nothing in Visual Basic) or is an empty string (""). |
| MessageQueueException | The syntax for the path parameter is invalid.
-or- An error occurred when accessing a Message Queuing API. |
Remarks
The syntax for the path parameter depends on the type of queue.
| Queue Type | Syntax |
|---|---|
| Public queue | MachineName\ QueueName |
| Private queue | MachineName\Private$\ QueueName |
For more syntax, see the Path property.
Alternatively, you can use the FormatName or Label to describe the queue path.
| Reference | Syntax |
|---|---|
| Format name | FormatName:[ format name ] |
| Label | Label:[ label ] |
The following table shows whether this method is available in various Workgroup modes.
| Workgroup Mode | Available |
|---|---|
| Local computer | No |
| Local computer + direct format name | No |
| Remote computer | No |
| Remote computer + direct format name | No |
Example
[Visual Basic, C#, C++] The following example deletes a Message Queuing queue, if it exists.
[Visual Basic] Imports System Imports System.Messaging Namespace MyProject '/ <summary> '/ Provides a container class for the example. '/ </summary> Public Class MyNewQueue '************************************************** ' Provides an entry point into the application. ' ' This example verifies existence and attempts to ' delete a queue. '************************************************** Public Shared Sub Main() ' Determine whether the queue exists. If MessageQueue.Exists(".\myQueue") Then Try ' Delete the queue. MessageQueue.Delete(".\myQueue") Catch e As MessageQueueException If e.MessageQueueErrorCode = _ MessageQueueErrorCode.AccessDenied Then Console.WriteLine("Access is denied. " _ + "Queue might be a system queue.") End If ' Handle other sources of exceptions as necessary. End Try End If Return End Sub 'Main End Class 'MyNewQueue End Namespace 'MyProject [C#] using System; using System.Messaging; namespace MyProject { /// <summary> /// Provides a container class for the example. /// </summary> public class MyNewQueue { //************************************************** // Provides an entry point into the application. // // This example verifies existence and attempts to // delete a queue. //************************************************** public static void Main() { // Determine whether the queue exists. if (MessageQueue.Exists(".\\myQueue")) { try { // Delete the queue. MessageQueue.Delete(".\\myQueue"); } catch(MessageQueueException e) { if(e.MessageQueueErrorCode == MessageQueueErrorCode.AccessDenied) { Console.WriteLine("Access is denied. " + "Queue might be a system queue."); } // Handle other sources of MessageQueueException. } } return; } } } [C++] #using <mscorlib.dll> #using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; int main() { // Determine whether the queue exists. if (MessageQueue::Exists(S".\\myQueue")) { try { // Delete the queue. MessageQueue::Delete(S".\\myQueue"); } catch (MessageQueueException* e) { if (e->MessageQueueErrorCode == MessageQueueErrorCode::AccessDenied) { Console::WriteLine(S"Access is denied. Queue might be a system queue."); } // Handle other sources of MessageQueueException. } } return 0; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries From Partially Trusted Code
See Also
MessageQueue Class | MessageQueue Members | System.Messaging Namespace | Create | Close | Path