MessageQueue.GetEnumerator 方法

定义

注意

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

枚举队列中的消息。 GetEnumerator() 已弃用。 应改用 GetMessageEnumerator2()

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

返回

IEnumerator,它提供与队列消息的动态连接。

实现

属性

示例

以下代码示例演示了 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);
}

注解

下表显示了此方法在各种工作组模式下是否可用。

工作组模式 可用
本地计算机
本地计算机和直接格式名称
远程计算机
远程计算机和直接格式名称

适用于

另请参阅