MessageQueue.Exists(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定消息队列队列是否存在于指定路径。
public:
static bool Exists(System::String ^ path);
public static bool Exists(string path);
static member Exists : string -> bool
Public Shared Function Exists (path As String) As Boolean
参数
- path
- String
要查找的队列的位置。
返回
true 如果存在具有指定路径的队列,则为 ;否则,为 false.
例外
语法 path 无效。
应用程序在验证队列存在时使用了格式名称语法。
示例
下面的代码示例验证消息队列队列队列是否存在,然后删除该队列。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
int 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 0;
}
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;
}
}
}
Imports System.Messaging
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
End Class
注解
该方法 Exists(String) 确定消息队列队列是否存在于指定路径。 不存在用于确定具有指定格式名称的队列是否存在的方法。 有关格式名称语法和其他路径语法表单的详细信息,请参阅属性 Path 。
Exists(String) 是一项昂贵的操作。 仅在应用程序内需要时才使用它。
注释
该方法 Exists(String) 不支持 FormatName 前缀。
参数的语法 path 取决于队列的类型,如下表所示。
| 队列类型 | Syntax |
|---|---|
| 公共队列 | MachineName\QueueName |
Exists(String) 无法调用来验证是否存在远程专用队列。
有关更多语法,请参阅属性 Path 。
或者,可以使用该 Label 路径来描述队列路径。
| 引用 | Syntax |
|---|---|
| 标签 | Label:[ label ] |
下表显示了此方法在各种工作组模式下是否可用。
| 工作组模式 | 可用 |
|---|---|
| 本地计算机 | 是的 |
| 本地计算机和直接格式名称 | 否 |
| 远程计算机 | 否 |
| 远程计算机和直接格式名称 | 否 |