MessageQueue.GetMessageQueueEnumerator Method ()


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

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

public static MessageQueueEnumerator GetMessageQueueEnumerator()

Return Value

Type: System.Messaging.MessageQueueEnumerator

A MessageQueueEnumerator that provides a dynamic listing of all the public message queues on the network.

This overload of GetMessageQueueEnumerator returns an enumeration of all the public queues that are on the network.

Because the cursor is associated with a dynamic listing, the enumeration reflects any modification you make to a queue list for queues deleted or added beyond the cursor's current position. Additions or deletion of queues located before the cursor's current position are not reflected. For example, the enumerator can automatically access a queue appended beyond the cursor position but not one inserted before that position. However, you can reset the enumeration, thereby moving the cursor back to the beginning of the list, by calling Reset for the MessageQueueEnumerator.

There is no defined ordering of queues in a network. An enumerator does not order them, for example, by computer, label, public or private status, or any other accessible criteria.

If you want a static snapshot of the queues on the network rather than a dynamic connection to them, call GetPublicQueues or GetPrivateQueuesByMachine(String). Each of these two methods returns an array of MessageQueue objects, which represent the queues at the time the method was called.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode


Local computer


Local computer and direct format name


Remote computer


Remote computer and direct format name


The following code 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.

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.


		// 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 = 

			// Move to the next queue and read its path.
				// Increase the count if priority is Lowest.

			// Display final count.
			Console.WriteLine("Number of public queues: " + 


.NET Framework
Available since 1.1
Return to top