MessageQueue.GetMessageEnumerator Metoda

Definicja

Przestroga

This method returns a MessageEnumerator that implements RemoveCurrent family of methods incorrectly. Please use GetMessageEnumerator2 instead.

Tworzy obiekt modułu wyliczającego dla wszystkich komunikatów w kolejce. GetMessageEnumerator() jest przestarzały. GetMessageEnumerator2() Zamiast tego należy użyć polecenia .

public:
 System::Messaging::MessageEnumerator ^ GetMessageEnumerator();
public System.Messaging.MessageEnumerator GetMessageEnumerator ();
[System.Obsolete("This method returns a MessageEnumerator that implements RemoveCurrent family of methods incorrectly. Please use GetMessageEnumerator2 instead.")]
public System.Messaging.MessageEnumerator GetMessageEnumerator ();
member this.GetMessageEnumerator : unit -> System.Messaging.MessageEnumerator
[<System.Obsolete("This method returns a MessageEnumerator that implements RemoveCurrent family of methods incorrectly. Please use GetMessageEnumerator2 instead.")>]
member this.GetMessageEnumerator : unit -> System.Messaging.MessageEnumerator
Public Function GetMessageEnumerator () As MessageEnumerator

Zwraca

Przechowujące MessageEnumerator komunikaty, które znajdują się w kolejce.

Atrybuty

Przykłady

Poniższy przykład kodu pobiera dynamiczną listę komunikatów w kolejce i zlicza wszystkie komunikaty z właściwością ustawioną Priority na MessagePriority.Lowestwartość .

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:
   void CountLowestPriority()
   {
      
      // Holds the count of Lowest priority messages.
      UInt32 numberItems = 0;
      
      // Connect to a queue.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
      
      // Get a cursor into the messages in the queue.
      MessageEnumerator^ myEnumerator = myQueue->GetMessageEnumerator();
      
      // Specify that the messages's priority should be read.
      myQueue->MessageReadPropertyFilter->Priority = true;
      
      // Move to the next message and examine its priority.
      while ( myEnumerator->MoveNext() )
      {
         
         // Increase the count if priority is Lowest.
         if ( myEnumerator->Current->Priority == MessagePriority::Lowest )
                  numberItems++;
      }

      
      // Display final count.
      Console::WriteLine( "Lowest priority messages: {0}", numberItems );
      return;
   }

};

int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   
   // Output the count of Lowest priority messages.
   myNewQueue->CountLowestPriority();
   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 uses a cursor to step through the
        // messages in a queue and counts the number of
        // Lowest priority messages.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Output the count of Lowest priority messages.
            myNewQueue.CountLowestPriority();
                        
            return;
        }

        //**************************************************
        // Iterates through messages in a queue and examines
        // their priority.
        //**************************************************
        
        public void CountLowestPriority()
        {
            // Holds the count of Lowest priority messages.
            uint numberItems = 0;

            // Connect to a queue.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");
    
            // Get a cursor into the messages in the queue.
            MessageEnumerator myEnumerator =
                myQueue.GetMessageEnumerator();

            // Specify that the messages's priority should be read.
            myQueue.MessageReadPropertyFilter.Priority = true;

            // Move to the next message and examine its priority.
            while(myEnumerator.MoveNext())
            {
                // Increase the count if priority is Lowest.
                if(myEnumerator.Current.Priority ==
                    MessagePriority.Lowest)
                    
                    numberItems++;
            }

            // Display final count.
            Console.WriteLine("Lowest priority messages: " +
                numberItems.ToString());
            
            return;
        }
    }
}
Imports System.Messaging

Public Class MyNewQueue


        
        ' Provides an entry point into the application.
        '		 
        ' This example uses a cursor to step through the
        ' messages in a queue and counts the number of 
        ' Lowest priority messages.
        

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Output the count of Lowest priority messages.
            myNewQueue.CountLowestPriority()

            Return

        End Sub


        
        ' Iterates through messages in a queue and examines
        ' their priority.
        

        Public Sub CountLowestPriority()

            ' Holds the count of Lowest priority messages.
            Dim numberItems As Int32 = 0

            ' Connect to a queue.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Get a cursor into the messages in the queue.
            Dim myEnumerator As MessageEnumerator = _
                myQueue.GetMessageEnumerator()

            ' Specify that the messages's priority should be read.
            myQueue.MessageReadPropertyFilter.Priority = True

            ' Move to the next message and examine its priority.
            While myEnumerator.MoveNext()

                ' Increase the count if the priority is Lowest.
                If myEnumerator.Current.Priority = _
                    MessagePriority.Lowest Then
                    numberItems += 1
                End If

            End While

            ' Display final count.
            Console.WriteLine(("Lowest priority messages: " + _
                numberItems.ToString()))

            Return

        End Sub

End Class

Uwagi

GetMessageEnumerator Tworzy dynamiczną listę wszystkich komunikatów w kolejce. Komunikat można usunąć z kolejki w bieżącej pozycji modułu wyliczającego, wywołując RemoveCurrent dla MessageEnumerator tej GetMessageEnumerator funkcji.

Ponieważ kursor jest skojarzony z dynamiczną listą komunikatów w kolejce, wyliczenie odzwierciedla wszelkie zmiany wprowadzone w komunikatach w kolejce, jeśli komunikat znajduje się poza bieżącym położeniem kursora. Na przykład moduł wyliczający może automatycznie uzyskać dostęp do komunikatu o niższym priorytcie umieszczonego poza bieżącą pozycją kursora, ale nie komunikat o wyższym priorytcie wstawiony przed tym położeniem. Można jednak zresetować wyliczenie, przenosząc kursor z powrotem na początek listy, wywołując Reset element MessageEnumerator.

Kolejność komunikatów w wyliczenie odzwierciedla ich kolejność w kolejce, więc komunikaty o wyższym priorytcie będą wyświetlane przed komunikatami o niższym priorytcie.

Jeśli chcesz utworzyć statyczną migawkę komunikatów w kolejce, a nie dynamiczne połączenie z nimi, wywołaj metodę GetAllMessages. Ta metoda zwraca tablicę Message obiektów, które reprezentują komunikaty w czasie wywołania metody.

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
Nazwa komputera lokalnego i bezpośredniego formatu Tak
Komputer zdalny Tak
Nazwa komputera zdalnego i bezpośredniego formatu Tak

Dotyczy

Zobacz też