MessageQueue.GetEnumerator Method

Definition

Caution

This method returns a MessageEnumerator that implements RemoveCurrent family of methods incorrectly. Please use GetMessageEnumerator2 instead.

Enumerates the messages in a queue. GetEnumerator() is deprecated. GetMessageEnumerator2() should be used instead.

public:
 virtual System::Collections::IEnumerator ^ GetEnumerator();
public System.Collections.IEnumerator GetEnumerator ();
[System.Obsolete("This method returns a MessageEnumerator that implements RemoveCurrent family of methods incorrectly. Please use GetMessageEnumerator2 instead.")]
public System.Collections.IEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
[<System.Obsolete("This method returns a MessageEnumerator that implements RemoveCurrent family of methods incorrectly. Please use GetMessageEnumerator2 instead.")>]
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Function GetEnumerator () As IEnumerator

Returns

A IEnumerator that provides a dynamic connection to the messages in the queue.

Implements

Attributes

Examples

The following code example demonstrates the use of GetEnumerator.


// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");

// Get an IEnumerator object.
System::Collections::IEnumerator^ enumerator = 
    queue->GetMessageEnumerator2();

// Use the IEnumerator object to loop through the messages.
while(enumerator->MoveNext())
{
    // Get a message from the enumerator.
    Message^ msg = (Message^)enumerator->Current;

    // Display the label of the message.
    Console::WriteLine(msg->Label);
}

queue->Close();

// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");

// Get an IEnumerator object.
System.Collections.IEnumerator enumerator = queue.GetEnumerator();

// Use the IEnumerator object to loop through the messages.
while(enumerator.MoveNext())
{
    // Get a message from the enumerator.
    Message msg = (Message)enumerator.Current;

    // Display the label of the message.
    Console.WriteLine(msg.Label);
}

Remarks

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

Workgroup mode Available
Local computer Yes
Local computer and direct format name Yes
Remote computer No
Remote computer and direct format name Yes

Applies to

See also