Bagikan melalui


MessageQueue.GetMessageEnumerator Metode

Definisi

Perhatian

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

Membuat objek enumerator untuk semua pesan dalam antrean. GetMessageEnumerator() tidak digunakan lagi. GetMessageEnumerator2() harus digunakan sebagai gantinya.

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

Mengembalikan

Yang MessageEnumerator menyimpan pesan yang terkandung dalam antrean.

Atribut

Contoh

Contoh kode berikut mendapatkan daftar pesan dinamis dalam antrean dan menghitung semua pesan dengan properti yang Priority diatur ke MessagePriority.Lowest.

#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

Keterangan

GetMessageEnumerator membuat daftar dinamis semua pesan dalam antrean. Anda dapat menghapus dari antrean pesan di posisi enumerator saat ini dengan memanggil RemoveCurrentMessageEnumerator yang GetMessageEnumerator kembali.

Karena kursor dikaitkan dengan daftar dinamis pesan dalam antrean, enumerasi mencerminkan modifikasi apa pun yang Anda lakukan pada pesan dalam antrean, jika pesan berada di luar posisi kursor saat ini. Misalnya, enumerator dapat secara otomatis mengakses pesan berprioritas lebih rendah yang ditempatkan di luar posisi kursor saat ini, tetapi bukan pesan berprioritas lebih tinggi yang disisipkan sebelum posisi tersebut. Namun, Anda dapat mengatur ulang enumerasi, sehingga memindahkan kursor kembali ke awal daftar, dengan memanggil ResetMessageEnumerator.

Urutan pesan dalam enumerasi mencerminkan urutannya dalam antrean, sehingga pesan berprioritas lebih tinggi akan muncul sebelum pesan berprioritas lebih rendah.

Jika Anda menginginkan rekam jepret statis pesan dalam antrean daripada koneksi dinamis ke pesan tersebut, panggil GetAllMessages. Metode ini mengembalikan array Message objek, yang mewakili pesan pada saat metode dipanggil.

Tabel berikut menunjukkan apakah metode ini tersedia dalam berbagai mode Grup Kerja.

Mode grup kerja Tersedia
Komputer lokal Ya
Komputer lokal dan nama format langsung Ya
Komputer jarak jauh Ya
Komputer jarak jauh dan nama format langsung Ya

Berlaku untuk

Lihat juga