語言

MessageQueue.Exists(String) 方法

定義

判斷指定路徑是否存在訊息佇列。

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 法不成立。

存取訊息佇列方法時發生錯誤。

-或-

該 Exists(String) 方法是在遠端私有佇列中被呼叫的

應用程式在驗證佇列存在時使用格式名稱語法。

範例

以下程式碼範例驗證訊息佇列是否存在,然後將其刪除。

#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) 是一項昂貴的操作。 只有在應用程式中必要時才使用。

Note

此Exists(String)方法不支援前綴。FormatName

參數的語法 path 依佇列類型而異,如下表所示。

佇列類型 語法
公共排隊 MachineName\QueueName

Exists(String) 無法呼叫以驗證遠端私有佇列的存在。

更多語法,請參見屬性。Path

或者,你也可以用 來 Label 描述佇列路徑。

Reference 語法
標籤 唱片公司:[ label ]

下表顯示此方法是否可在多種工作群組模式中使用。

工作群組模式 Available
本機電腦 Yes
本地電腦與直接格式名稱 No
遠端電腦 No
遠端電腦與直接格式名稱 No

適用於

另請參閱