MessageEnumerator クラス

定義

メッセージ キュー内のメッセージを列挙するための順方向専用カーソルを提供します。

public ref class MessageEnumerator : MarshalByRefObject, IDisposable, System::Collections::IEnumerator
public class MessageEnumerator : MarshalByRefObject, IDisposable, System.Collections.IEnumerator
type MessageEnumerator = class
    inherit MarshalByRefObject
    interface IEnumerator
    interface IDisposable
Public Class MessageEnumerator
Inherits MarshalByRefObject
Implements IDisposable, IEnumerator
継承
MessageEnumerator
実装

次の例では、キュー内のメッセージの動的な一覧を取得し、プロパティが Priority .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

注釈

キュー内のメッセージとの動的な対話に使用 MessageEnumerator します。 クラスで MessageQueue 使用できるメソッドは、キュー内のメッセージの動的なリストを指す、または指定されたメソッドが呼び出されたときのキューの特定の瞬間 (スナップショット) のコピーを含む配列を MessageEnumerator 返すことができます。

静的スナップショットとは異なり、列挙子を使用すると、コレクションを変更できます。 を MessageEnumerator使用すると、キューからメッセージを削除でき、変更はすぐにキューに反映されます。

列挙子は、キューに対してクエリを実行するときに、キューからメッセージを削除しません。 現在のカーソル位置にあるメッセージに関する情報を返しますが、メッセージはキューに残ります。

A MessageEnumerator は、動的リストの先頭に初期化されたカーソルです。 リストの順序は、メッセージの優先順位に従って、キュー内のメッセージの順序と同じです。 を呼び出 MoveNextすことによって、キュー内の最初のメッセージにカーソルを移動できます。 列挙子が初期化されたら、残りのメッセージをステップ フォワードするために使用 MoveNext できます。 タイムアウトをメソッドに渡すことによって、メッセージが使用可能になるのを MoveNext 待つかどうかを指定できます。

列挙子は動的であるため、カーソルの現在位置を超えて追加されるメッセージ (優先順位が低いためなど) には、列挙子からアクセスできます。 カーソルの現在位置の前に挿入されたメッセージにアクセスできません。 を使用 MessageEnumeratorして後方にステップバックすることはできません。 カーソルを使用すると、順方向専用の移動が可能になります。 この Reset メソッドを使用すると、キューの先頭にカーソルを戻します。

特定のキューの MessageEnumerator インスタンスは個別に動作します。 同じキューに適用される 2 つの MessageEnumerator インスタンスを作成できます。 キュー内のメッセージに対して行われる変更 MessageEnumerator は、2 番目の列挙子が最初の列挙子の前に配置されている場合、2 番目の列挙子に直ちに反映されます。 ただし、2 つの列挙子が同じ位置にあり、そのうちの 1 つがその位置にあるメッセージを削除した場合、もう一方の列挙子が削除されたメッセージのプロパティの Current 値を取得しようとすると、例外がスローされます。

注意

設定されたインスタンスMessageQueueMessageQueue.DenySharedReceiveを作成した場合、キューへのtrue接続中に列挙子内のメッセージを変更できるアプリケーションは他にありません。

プロパティ

Current

その列挙子が指している現在の Message を取得します。

CursorHandle

キュー内でメッセージを参照するために使われるネイティブなメッセージ キュー カーソル ハンドルを取得します。

メソッド

Close()

列挙子と関連付けられたリソースを解放します。

CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
Dispose()

MessageEnumerator によって使用されているすべてのリソースを解放します。

Dispose(Boolean)

MessageEnumerator によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
Finalize()

この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。

列挙子に保持されているリソースを解放します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
互換性のために残されています。

対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
互換性のために残されています。

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
MoveNext()

キュー内の次のメッセージに列挙子を進めます (そのメッセージが現在使用できる場合)。

MoveNext(TimeSpan)

キュー内の次のメッセージに列挙子を進めます。 列挙子がキューの最後に位置しているときは、MoveNext() は、メッセージが使用できるようになるか指定のタイムアウト時間が経過するまで待機します。

RemoveCurrent()

トランザクション キューまたは非トランザクション キューから現在のメッセージを削除し、そのメッセージを呼び出し元アプリケーションに返します。 メッセージがキューに到達するまでのタイムアウトは指定されていません。

RemoveCurrent(MessageQueueTransaction)

トランザクション キューから現在のメッセージを削除し、そのメッセージを呼び出し元アプリケーションに返します。 メッセージがキューに到達するまでのタイムアウトは指定されていません。

RemoveCurrent(MessageQueueTransactionType)

キューから現在のメッセージを削除し、そのメッセージを呼び出し元アプリケーションに返します。 メッセージがキューに到達するまでのタイムアウトは指定されていません。

RemoveCurrent(TimeSpan)

キューから現在のメッセージを削除し、そのメッセージを呼び出し元アプリケーションに返します。 削除するメッセージがある場合、メソッドはすぐにメッセージを返します。 削除するメッセージがない場合、メソッドは新しいメッセージが到達するまで指定のタイムアウト時間だけ待機します。

RemoveCurrent(TimeSpan, MessageQueueTransaction)

トランザクション キューから現在のメッセージを削除し、そのメッセージを呼び出し元アプリケーションに返します。 削除するメッセージがある場合、メソッドはすぐにメッセージを返します。 削除するメッセージがない場合、メソッドは新しいメッセージが到達するまで指定のタイムアウト時間だけ待機します。

RemoveCurrent(TimeSpan, MessageQueueTransactionType)

キューから現在のメッセージを削除し、そのメッセージを呼び出し元アプリケーションに返します。 削除するメッセージがある場合、メソッドはすぐにメッセージを返します。 削除するメッセージがない場合、メソッドは新しいメッセージが到達するまで指定のタイムアウト時間だけ待機します。

Reset()

キューの先頭を指すように現在の列挙子をリセットします。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

IEnumerator.Current

現在のカーソル位置にあるメッセージを参照する Message を返します。

適用対象

こちらもご覧ください