MessageQueue.Exists Method
Determines whether a Message Queuing queue at the specified path exists.
[Visual Basic] Public Shared Function Exists( _ ByVal path As String _ ) As Boolean [C#] public static bool Exists( string path ); [C++] public: static bool Exists( String* path ); [JScript] public static function Exists( path : String ) : Boolean;
Parameters
- path
- The location of the queue to find.
Return Value
true if a queue with the specified path exists; otherwise, false.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentException | The path syntax is invalid. |
| MessageQueueException | An error occurred when accessing a Message Queuing API.
-or- The Exists method is being called on a remote private queue |
| InvalidOperationException | The application used a format name syntax when verifying queue existence. |
Remarks
The Exists method determines whether a Message Queuing queue exists at a specified path. No method exists to determine whether a queue with a specified format name exists. For more information about the format name syntax and other path syntax forms, see the Path property.)
Exists is an expensive operation. Use it only when it is necessary within the application.
The syntax for the path parameter depends on the type of queue.
| Queue Type | Syntax |
|---|---|
| Public queue | MachineName\ QueueName |
Note Exists cannot be called to verify the existence of a remote private queue.
For more syntax, see the Path property.
Alternatively, you can use the Label to describe the queue path.
| Reference | Syntax |
|---|---|
| Label | Label:[ label ] |
The following table shows whether this method is available in various Workgroup modes.
| Workgroup Mode | Available |
|---|---|
| Local computer | Yes |
| Local computer + direct format name | No |
| Remote computer | No |
| Remote computer + direct format name | No |
Example
[Visual Basic, C#, C++] The following example verifies whether a Message Queuing queue exists, and then deletes it.
[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 | Delete | Path