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 使用してキュー パスを記述することもできます。

関連項目 構文
ラベル Label:[ label ]

次の表は、このメソッドがさまざまなワークグループ モードで使用できるかどうかを示しています。

ワークグループ モード 利用可能
ローカル コンピューター はい
ローカル コンピューターと直接の形式名 いいえ
リモート コンピューター いいえ
リモート コンピューターと直接形式の名前 いいえ

適用対象

こちらもご覧ください