Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

MessageQueue.GetMessageQueueEnumerator Method

Creates an enumerator object for a dynamic listing of the public queues on the network.

Overload List

Provides forward-only cursor semantics to enumerate through all public queues on the network.

[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;

Provides forward-only cursor semantics to enumerate through all public queues on the network that meet the specified criteria.

[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;

Example

[Visual Basic, C#, C++] The following example 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".

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetMessageQueueEnumerator. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace

Show:
© 2015 Microsoft