MessageQueue.GetMessageEnumerator 메서드

정의

주의

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

큐에 있는 모든 메시지에 대해 열거자 개체를 만듭니다. GetMessageEnumerator()는 사용되지 않습니다. GetMessageEnumerator2()를 대신 사용해야 합니다.

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

반환

큐에 있는 메시지를 보유하는 MessageEnumerator를 반환합니다.

특성

예제

다음 코드 예제에서는 큐에 있는 메시지의 동적 목록을 가져오고 속성이 로 설정된 MessagePriority.Lowest모든 메시지를 Priority 계산합니다.

#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

설명

GetMessageEnumerator 는 큐에 있는 모든 메시지의 동적 목록을 만듭니다. 를 호출 RemoveCurrentMessageEnumeratorGetMessageEnumerator 하여 열거자의 현재 위치에 있는 메시지를 큐에서 제거할 수 있습니다.

커서는 큐의 동적 메시지 목록과 연결되므로 메시지가 현재 커서 위치를 벗어나면 열거형은 큐의 메시지에 대해 수정한 내용을 반영합니다. 예를 들어 열거자는 커서의 현재 위치보다 우선 순위가 낮은 메시지에 자동으로 액세스할 수 있지만 해당 위치 앞에 삽입된 우선 순위가 높은 메시지는 액세스할 수 없습니다. 그러나 를 호출 ResetMessageEnumerator하여 열거형을 다시 설정하여 커서를 목록의 시작 부분으로 다시 이동할 수 있습니다.

열거형의 메시지 순서는 큐의 순서를 반영하므로 우선 순위가 높은 메시지가 우선 순위가 낮은 메시지 앞에 표시됩니다.

동적 연결이 아닌 큐에 있는 메시지의 정적 스냅샷 하려면 를 호출GetAllMessages합니다. 이 메서드는 메서드가 호출된 당시의 메시지를 나타내는 개체 배열 Message 을 반환합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
수집 Yes
로컬 컴퓨터 및 직접 형식 이름 Yes
원격 컴퓨터 Yes
원격 컴퓨터 및 직접 형식 이름 Yes

적용 대상

추가 정보