TechNet
Export (0) Print
Expand All

MessageQueueEnumerator Class

 

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

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

System.Object
  System.MarshalByRefObject
    System.Messaging.MessageQueueEnumerator

public class MessageQueueEnumerator : MarshalByRefObject, IEnumerator, 
	IDisposable

NameDescription
System_CAPS_pubpropertyCurrent

Gets the current MessageQueue of the enumeration.

System_CAPS_pubpropertyLocatorHandle

Gets the native Message Queuing handle used to locate queues in a network.

NameDescription
System_CAPS_pubmethodClose()

Frees the resources associated with the enumerator.

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

Releases all resources used by the MessageQueueEnumerator.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the MessageQueueEnumerator and optionally releases the managed resources.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodMoveNext()

Advances the enumerator to the next queue of the enumeration, if one is currently available.

System_CAPS_pubmethodReset()

Resets the cursor, so it points to the beginning of the enumeration.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEnumerator.Current

Gets the current MessageQueue of the enumeration.

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.

There is no defined ordering of queues in a network. They are not ordered, for example, by computer, label, public or 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.

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.
			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;
		}
	}
}

.NET Framework
Available since 1.1

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

Return to top
Show:
© 2016 Microsoft