MessageQueue.GetMessageQueueEnumerator 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立一個列舉器物件,用於動態列出網路上公開佇列。
多載
| 名稱 | Description |
|---|---|
| GetMessageQueueEnumerator() |
提供僅向前的游標語意,以便在網路上所有公開佇列中枚舉。 |
| GetMessageQueueEnumerator(MessageQueueCriteria) |
提供僅向前的游標語意,以枚舉網路上所有符合指定條件的公共佇列。 |
GetMessageQueueEnumerator()
提供僅向前的游標語意,以便在網路上所有公開佇列中枚舉。
public:
static System::Messaging::MessageQueueEnumerator ^ GetMessageQueueEnumerator();
public static System.Messaging.MessageQueueEnumerator GetMessageQueueEnumerator();
static member GetMessageQueueEnumerator : unit -> System.Messaging.MessageQueueEnumerator
Public Shared Function GetMessageQueueEnumerator () As MessageQueueEnumerator
傳回
MessageQueueEnumerator A 提供網路上所有公開訊息隊列的動態清單。
範例
以下程式碼範例遍歷網路中所有訊息佇列,並檢視每個佇列的路徑。 最後,它會顯示網路上的公共佇列數量。
#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
備註
此過載 GetMessageQueueEnumerator 會回傳網路上所有公用佇列的列舉。
由於游標與動態列表相關聯,列舉會反映你對隊列清單所做的任何修改,針對已刪除或新增超出游標目前位置的佇列。 新增或刪除位於游標當前位置之前的隊列不會被反映。 例如,列舉器可以自動存取附加在游標位置之外的佇列,但無法存取該位置之前插入的佇列。 不過,你可以透過呼叫 ResetMessageQueueEnumerator。
網路中沒有明確的佇列順序。 列舉器不會依電腦、標籤、公開或私有狀態或其他可存取的標準排序。
如果你想要網路上佇列的靜態快照,而不是動態連線,請呼叫 GetPublicQueues 或 GetPrivateQueuesByMachine(String)。 這兩個方法各自回傳一個物件陣列 MessageQueue ,代表呼叫時的佇列。
下表顯示此方法是否可在多種工作群組模式中使用。
| 工作群組模式 | Available |
|---|---|
| 本機電腦 | No |
| 本地電腦與直接格式名稱 | No |
| 遠端電腦 | No |
| 遠端電腦與直接格式名稱 | No |
另請參閱
適用於
GetMessageQueueEnumerator(MessageQueueCriteria)
提供僅向前的游標語意,以枚舉網路上所有符合指定條件的公共佇列。
public:
static System::Messaging::MessageQueueEnumerator ^ GetMessageQueueEnumerator(System::Messaging::MessageQueueCriteria ^ criteria);
public static System.Messaging.MessageQueueEnumerator GetMessageQueueEnumerator(System.Messaging.MessageQueueCriteria criteria);
static member GetMessageQueueEnumerator : System.Messaging.MessageQueueCriteria -> System.Messaging.MessageQueueEnumerator
Public Shared Function GetMessageQueueEnumerator (criteria As MessageQueueCriteria) As MessageQueueEnumerator
參數
- criteria
- MessageQueueCriteria
MessageQueueCriteria A 包含用來篩選可用訊息佇列的條件。
傳回
MessageQueueEnumerator A 提供網路上符合參數限制criteria的公開訊息佇列動態列表。
範例
以下程式碼範例遍歷訊息佇列,並顯示每個在過去一天建立且存在於「MyComputer」電腦上的佇列路徑。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:
// Iterates through message queues and displays the
// path of each queue that was created in the last
// day and that exists on the computer "MyComputer".
void ListPublicQueuesByCriteria()
{
UInt32 numberQueues = 0;
// Specify the criteria to filter by.
MessageQueueCriteria^ myCriteria = gcnew MessageQueueCriteria;
myCriteria->MachineName = "MyComputer";
myCriteria->CreatedAfter = DateTime::Now.Subtract( TimeSpan(1,0,0,0) );
// Get a cursor into the queues on the network.
MessageQueueEnumerator^ myQueueEnumerator = MessageQueue::GetMessageQueueEnumerator( myCriteria );
// 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++;
}
// Handle no queues matching the criteria.
if ( numberQueues == 0 )
{
Console::WriteLine( "No public queues match criteria." );
}
return;
}
};
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Output the count of Lowest priority messages.
myNewQueue->ListPublicQueuesByCriteria();
return 0;
}
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 that specify certain criteria.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Output the count of Lowest priority messages.
myNewQueue.ListPublicQueuesByCriteria();
return;
}
//**************************************************
// Iterates through message queues and displays the
// path of each queue that was created in the last
// day and that exists on the computer "MyComputer".
//**************************************************
public void ListPublicQueuesByCriteria()
{
uint numberQueues = 0;
// Specify the criteria to filter by.
MessageQueueCriteria myCriteria = new
MessageQueueCriteria();
myCriteria.MachineName = "MyComputer";
myCriteria.CreatedAfter = DateTime.Now.Subtract(new
TimeSpan(1,0,0,0));
// Get a cursor into the queues on the network.
MessageQueueEnumerator myQueueEnumerator =
MessageQueue.GetMessageQueueEnumerator(myCriteria);
// 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++;
}
// Handle no queues matching the criteria.
if (numberQueues == 0)
{
Console.WriteLine("No public queues match criteria.");
}
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 that specify certain criteria.
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue()
' Output the count of Lowest priority messages.
myNewQueue.ListPublicQueuesByCriteria()
Return
End Sub
' Iterates through message queues and displays the
' path of each queue that was created in the last
' day and that exists on the computer "MyComputer".
Public Sub ListPublicQueuesByCriteria()
Dim numberQueues As Int32 = 0
' Specify the criteria to filter by.
Dim myCriteria As New MessageQueueCriteria()
myCriteria.MachineName = "MyComputer"
myCriteria.CreatedAfter = DateTime.Now.Subtract(New _
TimeSpan(1, 0, 0, 0))
' Get a cursor into the queues on the network.
Dim myQueueEnumerator As MessageQueueEnumerator = _
MessageQueue.GetMessageQueueEnumerator(myCriteria)
' 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
' Handle no queues matching the criteria.
If numberQueues = 0 Then
Console.WriteLine("No queues match the criteria.")
End If
Return
End Sub
End Class
備註
此過載 GetMessageQueueEnumerator 會回傳網路上所有符合應用條件的公共佇列清單。 你可以指定條件,例如佇列建立或修改時間、電腦名稱、標籤、分類,或這些組合。
由於游標與動態列表相關聯,列舉會反映你對列隊所做的任何超出游標當前位置的修改。 游標之前佇列的變動不會反映在當前位置。 例如,列舉器可以自動存取附加在游標位置之外的佇列,但無法存取該位置之前插入的佇列。 不過,你可以透過呼叫 ResetMessageQueueEnumerator。
網路中沒有明確的佇列順序。 列舉器不會依電腦、標籤、公開或私有狀態或其他可存取的標準排序。
如果你想要網路上佇列的靜態快照,而非動態連線,請指定條件或 GetPublicQueues 呼叫 GetPrivateQueuesByMachine(String)。 這兩個方法各自回傳一個物件陣列 MessageQueue ,代表呼叫時的佇列。 呼叫 、 或 分別以 、 LabelMachineName、 和 的過濾條件Category呼叫,結果相同GetPublicQueues。GetPublicQueuesByMachine(String)GetPublicQueuesByLabel(String)GetPublicQueuesByCategory(Guid)
下表顯示此方法是否可在多種工作群組模式中使用。
| 工作群組模式 | Available |
|---|---|
| 本機電腦 | No |
| 本地電腦與直接格式名稱 | No |
| 遠端電腦 | No |
| 遠端電腦與直接格式名稱 | No |