This documentation is archived and is not being maintained.

MessageQueue.GetMessageEnumerator2 Method

Note: This method is new in the .NET Framework version 2.0.

Creates an enumerator object for all the messages in the queue.

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

public MessageEnumerator GetMessageEnumerator2 ()
public MessageEnumerator GetMessageEnumerator2 ()
public function GetMessageEnumerator2 () : MessageEnumerator

Return Value

The MessageEnumerator holding the messages that are contained in the queue.

GetMessageEnumerator2 creates a dynamic list of all the messages in a queue. You can remove from the queue the message at the enumerator's current position by calling RemoveCurrent for the MessageEnumerator that GetMessageEnumerator2 returns.

Because the cursor is associated with the dynamic list of messages in the queue, the enumeration reflects any modification you make to the messages in the queue, if the message is beyond the current cursor position. For example, the enumerator can automatically access a lower-priority message placed beyond the cursor's current position, but not a higher-priority message 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 MessageEnumerator.

The order of the messages in the enumeration reflects their order in the queue, so higher-priority messages will appear before lower-priority ones.

If you want a static snapshot of the messages in the queue rather than a dynamic connection to them, call GetAllMessages. This method returns an array of Message objects, which represent the messages 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


  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0