MessageQueue.GetMessageEnumerator2 方法

定义

为队列中的所有消息创建枚举数对象。Creates an enumerator object for all the messages in the queue.

public:
 System::Messaging::MessageEnumerator ^ GetMessageEnumerator2();
public System.Messaging.MessageEnumerator GetMessageEnumerator2 ();
member this.GetMessageEnumerator2 : unit -> System.Messaging.MessageEnumerator
Public Function GetMessageEnumerator2 () As MessageEnumerator

返回

MessageEnumerator

MessageEnumerator 包括队列中所包含的消息。The MessageEnumerator holding the messages that are contained in the queue.

注解

GetMessageEnumerator2 创建队列中所有消息的动态列表。GetMessageEnumerator2 creates a dynamic list of all the messages in a queue. 你可以通过调用返回的来从队列中删除消息,该消息位于枚举数的当前位置 RemoveCurrent MessageEnumerator GetMessageEnumerator2You 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. 但是,你可以通过调用来重置枚举,从而将游标移回列表的开头 Reset MessageEnumeratorHowever, 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.

如果希望队列中消息的静态快照而不是动态连接到它们,请调用 GetAllMessagesIf you want a static snapshot of the messages in the queue rather than a dynamic connection to them, call GetAllMessages. 此方法返回对象的数组 Message ,这些对象表示调用方法时的消息。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 可用Available
本地计算机Local computer Yes
本地计算机和直接格式名称Local computer and direct format name Yes
远程计算机Remote computer Yes
远程计算机和直接格式名称Remote computer and direct format name Yes

适用于

另请参阅