MessageQueueEnumerator 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供僅轉寄數據指標,以列舉消息佇列中的訊息。
public ref class MessageQueueEnumerator : MarshalByRefObject, IDisposable, System::Collections::IEnumerator
public class MessageQueueEnumerator : MarshalByRefObject, IDisposable, System.Collections.IEnumerator
type MessageQueueEnumerator = class
inherit MarshalByRefObject
interface IEnumerator
interface IDisposable
Public Class MessageQueueEnumerator
Inherits MarshalByRefObject
Implements IDisposable, IEnumerator
- 繼承
- 實作
範例
以下程式碼範例遍歷網路中所有訊息佇列,並檢視每個佇列的路徑。 最後,它會顯示網路上的公共佇列數量。
#using <System.dll>
#using <System.Messaging.dll>
using namespace System;
using namespace System::Messaging;
//**************************************************
// Iterates through message queues and examines the
// path for each queue. Also displays the number of
// public queues on the network.
//**************************************************
void ListPublicQueues()
{
// Holds the count of private queues.
int numberQueues = 0;
// Get a cursor into the queues on the network.
MessageQueueEnumerator^ myQueueEnumerator = MessageQueue::GetMessageQueueEnumerator();
// Move to the next queue and read its path.
while ( myQueueEnumerator->MoveNext() )
{
// Increase the count if priority is Lowest.
Console::WriteLine( myQueueEnumerator->Current->Path );
numberQueues++;
}
// Display final count.
Console::WriteLine( "Number of public queues: {0}", numberQueues );
return;
}
//**************************************************
// Provides an entry point into the application.
//
// This example uses a cursor to step through the
// message queues and list the public queues on the
// network.
//**************************************************
int main()
{
// Output the count of Lowest priority messages.
ListPublicQueues();
}
using System;
using System.Messaging;
namespace MyProject
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
//**************************************************
// Provides an entry point into the application.
//
// This example uses a cursor to step through the
// message queues and list the public queues on the
// network.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Output the count of Lowest priority messages.
myNewQueue.ListPublicQueues();
return;
}
//**************************************************
// Iterates through message queues and examines the
// path for each queue. Also displays the number of
// public queues on the network.
//**************************************************
public void ListPublicQueues()
{
// Holds the count of private queues.
uint numberQueues = 0;
// Get a cursor into the queues on the network.
MessageQueueEnumerator myQueueEnumerator =
MessageQueue.GetMessageQueueEnumerator();
// Move to the next queue and read its path.
while(myQueueEnumerator.MoveNext())
{
// Increase the count if priority is Lowest.
Console.WriteLine(myQueueEnumerator.Current.Path);
numberQueues++;
}
// Display final count.
Console.WriteLine("Number of public queues: " +
numberQueues.ToString());
return;
}
}
}
Imports System.Messaging
Public Class MyNewQueue
' Provides an entry point into the application.
'
' This example uses a cursor to step through the
' message queues and list the public queues on the
' network.
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue()
' Output the count of Lowest priority messages.
myNewQueue.ListPublicQueues()
Return
End Sub
' Iterates through message queues and examines the
' path for each queue. Also displays the number of
' public queues on the network.
Public Sub ListPublicQueues()
' Holds the count of private queues.
Dim numberQueues As Int32 = 0
' Get a cursor into the queues on the network.
Dim myQueueEnumerator As MessageQueueEnumerator = _
MessageQueue.GetMessageQueueEnumerator()
' Move to the next queue and read its path.
While myQueueEnumerator.MoveNext()
' Increase the count if the priority is Lowest.
Console.WriteLine(myQueueEnumerator.Current.Path)
numberQueues += 1
End While
' Display final count.
Console.WriteLine(("Number of public queues: " + _
numberQueues.ToString()))
Return
End Sub
End Class
備註
用於 MessageQueueEnumerator 與網路佇列的動態互動。 透過該 MessageQueue 類別可用的方法可以回傳包含動態佇列清單的 , MessageQueueEnumerator 或是陣列,該陣列包含指定方法被呼叫時的佇列集合快照。
網路中沒有明確的佇列順序。 例如,它們不會依電腦、標籤、公開或私有狀態或其他使用者可及標準排序。 A MessageQueueEnumerator 是一個游標,初始化為動態列表的開頭。 你可以透過呼叫 MoveNext將游標移動到列舉的第一個佇列。 列舉器初始化後,你可以繼續 MoveNext 向前跨越剩餘的佇列。
無法用 後退。MessageQueueEnumerator 游標只允許在佇列列舉中前進。 不過,你可以呼叫 Reset 重置列舉,並將游標重新放在列表開頭。 由於列舉器是動態的,列舉器可以存取超出游標當前位置的隊列。 在游標目前位置之前插入的隊列,必須先呼叫重置才能存取。
屬性
| 名稱 | Description |
|---|---|
| Current |
取得列舉的電流 MessageQueue 。 |
| LocatorHandle |
取得用於網路中佇列的原生訊息佇列句柄。 |
方法
| 名稱 | Description |
|---|---|
| Close() |
釋放與普查器相關的資源。 |
| CreateObjRef(Type) |
建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。 (繼承來源 MarshalByRefObject) |
| Dispose() |
釋放 MessageQueueEnumerator所使用的所有資源。 |
| Dispose(Boolean) |
釋放 未管理的資源, MessageQueueEnumerator 並可選擇性地釋放受管理資源。 |
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| Finalize() |
釋放佇列中持有的資源。 |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetLifetimeService() |
已淘汰.
擷取控制這個實例存留期原則的目前存留期服務物件。 (繼承來源 MarshalByRefObject) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| InitializeLifetimeService() |
已淘汰.
取得存留期服務物件,以控制這個實例的存留期原則。 (繼承來源 MarshalByRefObject) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| MemberwiseClone(Boolean) |
建立目前 MarshalByRefObject 對象的淺層複本。 (繼承來源 MarshalByRefObject) |
| MoveNext() |
如果列舉器目前有下一個佇列可用,則會將列舉器推進到下一個佇列。 |
| Reset() |
重置游標,使其指向列舉的起點。 |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| IEnumerator.Current |
取得列舉的電流 MessageQueue 。 |