Export (0) Print
Expand All

MessageQueueEnumerator Class

Provides a forward-only cursor to enumerate through messages in a message queue.

For a list of all members of this type, see MessageQueueEnumerator Members.

System.Object
   System.MarshalByRefObject
      System.Messaging.MessageQueueEnumerator

[Visual Basic]
Public Class MessageQueueEnumerator
   Inherits MarshalByRefObject
   Implements IEnumerator, IDisposable
[C#]
public class MessageQueueEnumerator : MarshalByRefObject,
   IEnumerator, IDisposable
[C++]
public __gc class MessageQueueEnumerator : public
   MarshalByRefObject, IEnumerator, IDisposable
[JScript]
public class MessageQueueEnumerator extends MarshalByRefObject
   implements IEnumerator, IDisposable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Use MessageQueueEnumerator for dynamic interaction with queues on the network. Methods available through the MessageQueue class can return either a MessageQueueEnumerator containing a dynamic list of queues, or an array that contains a snapshot of the queue collection at the time the specified method was called.

Note   There is no defined ordering of queues in a network. They are not ordered, for example, by computer, label, public/private status, or other user-accessible criteria. A MessageQueueEnumerator is a cursor, initialized to the head of a dynamic list. You can move the cursor to the first queue of the enumeration by calling MoveNext. After the enumerator has been initialized, you can use MoveNext to step forward through the remaining queues.

It is not possible to step backward with a MessageQueueEnumerator. A cursor only allows forward movement through the queue enumeration. However, you can call Reset to reset the enumeration and put the cursor at the beginning of the list again. Because the enumerator is dynamic, a queue that is appended beyond the cursor's current position can be accessed by the enumerator. A queue that is inserted before the cursor's current position cannot be accessed without first calling Reset.

Example

[Visual Basic, C#, C++] The following example iterates through all the message queues in the network, and examines the path for each queue. Finally, it displays the number of public queues on the network.

[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.
        '**************************************************

        Public Shared Sub Main()

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

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

            Return

        End Sub 'Main


        '**************************************************
        ' Iterates through message queues and examines the
        ' path for each queue. Also displays the number of
        ' public queues on the network.
        '**************************************************

        Public Sub ListPublicQueues()

            ' Holds the count of private queues.
            Dim numberQueues As Int32 = 0

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

            ' 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

            ' Display final count.
            Console.WriteLine(("Number of public queues: " + _
                numberQueues.ToString()))

            Return

        End Sub 'ListPublicQueues

    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.
        //**************************************************

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

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


        //**************************************************
        // Iterates through message queues and examines the
        // path for each queue. Also displays the number of
        // public queues on the network.
        //**************************************************
        
        public void ListPublicQueues()
        {
            // Holds the count of private queues.
            uint numberQueues = 0;
    
            // Get a cursor into the queues on the network.
            MessageQueueEnumerator myQueueEnumerator = 
                MessageQueue.GetMessageQueueEnumerator();

            // 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++;
            }

            // Display final count.
            Console.WriteLine("Number of public queues: " + 
                numberQueues.ToString());
            
            return;
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Messaging.dll>
using namespace System;
using namespace System::Messaging;

//**************************************************
// Iterates through message queues and examines the
// path for each queue. Also displays the number of
// public queues on the network.
//**************************************************

void ListPublicQueues()
{
    // Holds the count of private queues.
    int numberQueues = 0;

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

    // 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++;
    }

    // Display final count.
    Console::WriteLine(S"Number of public queues: {0}", __box(numberQueues));

    return;
}

//**************************************************
// 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.
//**************************************************

int main()
{
    // Output the count of Lowest priority messages.
    ListPublicQueues();
}

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

Requirements

Namespace: System.Messaging

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Messaging (in System.Messaging.dll)

See Also

MessageQueueEnumerator Members | System.Messaging Namespace | MessageQueue | MessageQueue.GetMessageQueueEnumerator

Show:
© 2014 Microsoft