MessageQueue.Exists(String) Metoda

Definicja

Określa, czy kolejka kolejkowania komunikatów istnieje w określonej ścieżce.

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

Parametry

path
String

Lokalizacja kolejki do znalezienia.

Zwraca

true jeśli istnieje kolejka z określoną ścieżką; w przeciwnym razie , false.

Wyjątki

Składnia jest nieprawidłowa path .

Wystąpił błąd podczas uzyskiwania dostępu do metody kolejkowania komunikatów.

-lub-

Metoda Exists(String) jest wywoływana w zdalnej kolejce prywatnej

Aplikacja użyła składni nazwy formatu podczas weryfikowania istnienia kolejki.

Przykłady

Poniższy przykład kodu sprawdza, czy kolejka kolejkowania komunikatów istnieje, a następnie usuwa ją.

#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

Uwagi

Metoda Exists(String) określa, czy kolejka kolejkowania komunikatów istnieje w określonej ścieżce. Nie istnieje metoda określania, czy kolejka o określonej nazwie formatu istnieje. Aby uzyskać więcej informacji na temat składni nazwy formatu i innych formularzy składni ścieżki, zobacz Path właściwość.

Exists(String) jest kosztowną operacją. Należy używać go tylko wtedy, gdy jest to konieczne w aplikacji.

Uwaga

Metoda Exists(String) nie obsługuje prefiksu FormatName .

Składnia parametru path zależy od typu kolejki, jak pokazano w poniższej tabeli.

Typ kolejki Składnia
Kolejka publiczna MachineName\QueueName

Exists(String) Nie można wywołać wywołania w celu zweryfikowania istnienia zdalnej kolejki prywatnej.

Aby uzyskać więcej składni, zobacz Path właściwość .

Alternatywnie możesz użyć polecenia Label , aby opisać ścieżkę kolejki.

Odwołanie Składnia
Etykieta Label:[ label ]

W poniższej tabeli przedstawiono, czy ta metoda jest dostępna w różnych trybach grupy roboczej.

Tryb grupy roboczej Dostępne
Komputer lokalny Tak
Komputer lokalny i nazwa formatu bezpośredniego Nie
Komputer zdalny Nie
Nazwa komputera zdalnego i formatu bezpośredniego Nie

Dotyczy

Zobacz też