共用方式為


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

備註

下表顯示這個方法是否可在各種工作組模式中使用。

工作組模式 可用
本機電腦
本機計算機和直接格式名稱
遠端電腦
遠端電腦和直接格式名稱

適用於

另請參閱