次の方法で共有


MessageQueue.GetMessageQueueEnumerator メソッド

列挙子オブジェクトを作成し、ネットワーク上のパブリック キューの動的リストを作成します。

オーバーロードの一覧

ネットワーク上のすべてのパブリック キューを列挙するための前方向カーソル セマンティクスをサポートします。

[Visual Basic] Overloads Public Shared Function GetMessageQueueEnumerator() As MessageQueueEnumerator

[C#] public static MessageQueueEnumerator GetMessageQueueEnumerator();

[C++] public: static MessageQueueEnumerator* GetMessageQueueEnumerator();

[JScript] public static function GetMessageQueueEnumerator() : MessageQueueEnumerator;

指定した基準を満たすネットワーク上のすべてのパブリック キューを列挙するための前方向カーソル セマンティクスをサポートします。

[Visual Basic] Overloads Public Shared Function GetMessageQueueEnumerator(MessageQueueCriteria) As MessageQueueEnumerator

[C#] public static MessageQueueEnumerator GetMessageQueueEnumerator(MessageQueueCriteria);

[C++] public: static MessageQueueEnumerator* GetMessageQueueEnumerator(MessageQueueCriteria*);

[JScript] public static function GetMessageQueueEnumerator(MessageQueueCriteria) : MessageQueueEnumerator;

使用例

[Visual Basic, C#, C++] 一連のメッセージ キューを反復処理し、1 日前に作成され、"MyComputer" という名前のコンピュータ上に存在するキューのパスを表示する例を次に示します。

[Visual Basic, C#, C++] メモ   ここでは、GetMessageQueueEnumerator のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Imports System
Imports 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
        ' message queues and list the public queues on the
        ' network that specify certain criteria.
        '**************************************************

        Public Shared Sub Main()

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

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

            Return

        End Sub 'Main


        '**************************************************
        ' Iterates through message queues and displays the
        ' path of each queue that was created in the last
        ' day and that exists on the computer "MyComputer". 
        '**************************************************

        Public Sub ListPublicQueuesByCriteria()

            Dim numberQueues As Int32 = 0

            ' Specify the criteria to filter by.
            Dim myCriteria As New MessageQueueCriteria()
            myCriteria.MachineName = "MyComputer"
            myCriteria.CreatedAfter = DateTime.Now.Subtract(New _
                TimeSpan(1, 0, 0, 0))


            ' Get a cursor into the queues on the network.
            Dim myQueueEnumerator As MessageQueueEnumerator = _
                MessageQueue.GetMessageQueueEnumerator(myCriteria)

            ' Move to the next queue and read its path.
            While myQueueEnumerator.MoveNext()
                ' Increase the count if the priority is Lowest.
                Console.WriteLine(myQueueEnumerator.Current.Path)
                numberQueues += 1
            End While

            ' Handle no queues matching the criteria.
            If numberQueues = 0 Then
                Console.WriteLine("No queues match the criteria.")
            End If

            Return

        End Sub 'ListPublicQueuesByCriteria

    End Class 'MyNewQueue
End Namespace 'MyProject

[C#] 
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
        // message queues and list the public queues on the
        // network that specify certain criteria.
        //**************************************************

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

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


        //**************************************************
        // Iterates through message queues and displays the
        // path of each queue that was created in the last
        // day and that exists on the computer "MyComputer". 
        //**************************************************
        
        public void ListPublicQueuesByCriteria()
        {
            uint numberQueues = 0;
            
            // Specify the criteria to filter by.
            MessageQueueCriteria myCriteria = new 
                MessageQueueCriteria();
            myCriteria.MachineName = "MyComputer";
            myCriteria.CreatedAfter = DateTime.Now.Subtract(new 
                TimeSpan(1,0,0,0));
    

            // Get a cursor into the queues on the network.
            MessageQueueEnumerator myQueueEnumerator = 
                MessageQueue.GetMessageQueueEnumerator(myCriteria);

            // Move to the next queue and read its path.
            while(myQueueEnumerator.MoveNext())
            {
                // Increase the count if priority is Lowest.
                Console.WriteLine(myQueueEnumerator.Current.Path);
                numberQueues++;
            }

            // Handle no queues matching the criteria.
            if (numberQueues == 0)
            {
                Console.WriteLine("No public queues match criteria.");
            }

            return;
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

__gc class MyNewQueue 
{
    // Iterates through message queues and displays the
    // path of each queue that was created in the last
    // day and that exists on the computer "MyComputer". 

public:
    void ListPublicQueuesByCriteria() 
    {
        UInt32 numberQueues = 0;

        // Specify the criteria to filter by.
        MessageQueueCriteria* myCriteria = new MessageQueueCriteria();
        myCriteria->MachineName = S"MyComputer";
        myCriteria->CreatedAfter = DateTime::Now.Subtract(TimeSpan(1, 0, 0, 0));

        // Get a cursor into the queues on the network.
        MessageQueueEnumerator* myQueueEnumerator = 
            MessageQueue::GetMessageQueueEnumerator(myCriteria);

        // Move to the next queue and read its path.
        while(myQueueEnumerator->MoveNext()) 
        {
            // Increase the count if priority is Lowest.
            Console::WriteLine(myQueueEnumerator->Current->Path);
            numberQueues++;
        }

        // Handle no queues matching the criteria.
        if (numberQueues == 0) 
        {
            Console::WriteLine(S"No public queues match criteria.");
        }

        return;
    }
};

int main() 
{
    // Create a new instance of the class.
    MyNewQueue* myNewQueue = new MyNewQueue();

    // Output the count of Lowest priority messages.
    myNewQueue->ListPublicQueuesByCriteria();

    return 0;
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

MessageQueue クラス | MessageQueue メンバ | System.Messaging 名前空間