MessageQueue.Exists(String) 方法

定義

判斷指定路徑上是否存在訊息佇列。Determines whether a Message Queuing queue exists at the specified path.

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

要尋找的佇列位置。The location of the queue to find.

傳回

Boolean

如果指定路徑上的佇列存在則為 true,否則為 falsetrue if a queue with the specified path exists; otherwise, false.

例外狀況

path 語法無效。The path syntax is not valid.

存取訊息佇列方法時發生錯誤。An error occurred when accessing a Message Queuing method.

-或--or- Exists(String) 方法會在遠端私用佇列上呼叫。The Exists(String) method is being called on a remote private queue

確認佇列是否存在時,應用程式會使用格式名稱語法。The application used format name syntax when verifying queue existence.

範例

下列程式碼範例會確認訊息佇列佇列是否存在,然後將它刪除。The following code example verifies whether a Message Queuing queue exists, and then deletes it.

#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)方法會判斷訊息佇列佇列是否存在於指定的路徑。The Exists(String) 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. 如需格式名稱語法和其他路徑語法形式的詳細資訊,請參閱 Path 屬性。 ) For more information about the format name syntax and other path syntax forms, see the Path property.)

Exists(String) 是昂貴的作業。Exists(String) is an expensive operation. 只有在應用程式中需要時,才使用它。Use it only when it is necessary within the application.

注意

Exists(String)方法不支援 FormatName 前置詞。The Exists(String) method does not support the FormatName prefix.

參數的語法 path 取決於佇列的類型,如下表所示。The syntax for the path parameter depends on the type of queue, as shown in the following table.

佇列類型Queue type 語法Syntax
公用佇列Public queue MachineName\QueueName

Exists(String) 無法呼叫來確認遠端私用佇列是否存在。Exists(String) cannot be called to verify the existence of a remote private queue.

如需語法的詳細資訊,請參閱 Path 屬性。For more syntax, see the Path property.

或者,您可以使用 Label 來描述佇列路徑。Alternatively, you can use the Label to describe the queue path.

參考資料Reference 語法Syntax
標籤Label 標籤: [ label ]Label:[ label ]

下表顯示此方法是否適用于各種工作組模式。The following table shows whether this method is available in various Workgroup modes.

工作組模式Workgroup mode 可用Available
本機電腦Local computer Yes
本機電腦和直接格式名稱Local computer and direct format name No
遠端電腦Remote computer No
遠端電腦和直接格式名稱Remote computer and direct format name No

適用於

另請參閱