MessageQueue::GetPublicQueues Method (MessageQueueCriteria^)
Retrieves all the public queues on the network that meet the specified criteria.
Assembly: System.Messaging (in System.Messaging.dll)
Parameters
- criteria
-
Type:
System.Messaging::MessageQueueCriteria^
A MessageQueueCriteria that contains the criteria used to filter the queues.
Return Value
Type: array<System.Messaging::MessageQueue^>^An array of MessageQueue objects that reference the retrieved public queues.
| Exception | Condition |
|---|---|
| MessageQueueException | An error occurred when accessing a Message Queuing method. |
If you want to filter all the public queues on the network by label, category, or computer name, the MessageQueue class contains specific methods that provide that functionality (GetPublicQueuesByLabel(String^), GetPublicQueuesByCategory(Guid), and GetPublicQueuesByMachine(String^), respectively). Use this overload to get a list of all the public queues on the network that meet more than one of these criteria (for example, if you want to specify both a label and a category). You can also filter by message criteria other than Label, Category, and MachineName. For example, you use this overload to filter by a queue's last-modified time. Simply create a new instance of the MessageQueueCriteria class, set the appropriate properties in the instance, and pass the instance as the criteria parameter.
GetPublicQueues retrieves a static snapshot of the queues. To interact with a dynamic list of the queues, use GetMessageQueueEnumerator.
The following table shows whether this method is available in various Workgroup modes.
Workgroup mode | Available |
|---|---|
Local computer | No |
Local computer and direct format name | No |
Remote computer | No |
Remote computer and direct format name | No |
The following code example retrieves lists of queues.
#using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; using namespace System::Collections; ref class MyNewQueue { public: // Gets a list of queues with a specified category. // Sends a broadcast message to all queues in that // category. void GetQueuesByCategory() { // Get a list of queues with the specified category. array<MessageQueue^>^QueueList = MessageQueue::GetPublicQueuesByCategory( Guid(" {00000000-0000-0000-0000-000000000001}") ); // Send a broadcast message to each queue in the array. IEnumerator^ myEnum = QueueList->GetEnumerator(); while ( myEnum->MoveNext() ) { MessageQueue^ queueItem = safe_cast<MessageQueue^>(myEnum->Current); queueItem->Send( "Broadcast message." ); } return; } // Gets a list of queues with a specified label. // Sends a broadcast message to all queues with that // label. void GetQueuesByLabel() { // Get a list of queues with the specified label. array<MessageQueue^>^QueueList = MessageQueue::GetPublicQueuesByLabel( "My Label" ); // Send a broadcast message to each queue in the array. IEnumerator^ myEnum = QueueList->GetEnumerator(); while ( myEnum->MoveNext() ) { MessageQueue^ queueItem = safe_cast<MessageQueue^>(myEnum->Current); queueItem->Send( "Broadcast message." ); } return; } // Gets a list of queues on a specified computer. // Displays the list on screen. void GetQueuesByComputer() { // Get a list of queues on the specified computer. array<MessageQueue^>^QueueList = MessageQueue::GetPublicQueuesByMachine( "MyComputer" ); // Display the paths of the queues in the list. IEnumerator^ myEnum = QueueList->GetEnumerator(); while ( myEnum->MoveNext() ) { MessageQueue^ queueItem = safe_cast<MessageQueue^>(myEnum->Current); Console::WriteLine( queueItem->Path ); } return; } // Gets a list of all public queues. void GetAllPublicQueues() { // Get a list of public queues. array<MessageQueue^>^QueueList = MessageQueue::GetPublicQueues(); return; } // Gets a list of all public queues that match // specified criteria. Displays the list on // screen. void GetPublicQueuesByCriteria() { // Define criteria to filter the queues. MessageQueueCriteria^ myCriteria = gcnew MessageQueueCriteria; myCriteria->CreatedAfter = DateTime::Now.Subtract( TimeSpan(1,0,0,0) ); myCriteria->ModifiedBefore = DateTime::Now; myCriteria->MachineName = "."; myCriteria->Label = "My Queue"; // Get a list of queues with that criteria. array<MessageQueue^>^QueueList = MessageQueue::GetPublicQueues( myCriteria ); // Display the paths of the queues in the list. IEnumerator^ myEnum = QueueList->GetEnumerator(); while ( myEnum->MoveNext() ) { MessageQueue^ queueItem = safe_cast<MessageQueue^>(myEnum->Current); Console::WriteLine( queueItem->Path ); } return; } // Gets a list of private queues on the local // computer. Displays the list on screen. void GetPrivateQueues() { // Get a list of queues with the specified category. array<MessageQueue^>^QueueList = MessageQueue::GetPrivateQueuesByMachine( "." ); // Display the paths of the queues in the list. IEnumerator^ myEnum = QueueList->GetEnumerator(); while ( myEnum->MoveNext() ) { MessageQueue^ queueItem = safe_cast<MessageQueue^>(myEnum->Current); Console::WriteLine( queueItem->Path ); } return; } }; // Provides an entry point into the application. // This example gets lists of queues by a variety // of criteria. int main() { // Create a new instance of the class. MyNewQueue^ myNewQueue = gcnew MyNewQueue; // Send normal and high priority messages. myNewQueue->GetQueuesByCategory(); myNewQueue->GetQueuesByLabel(); myNewQueue->GetQueuesByComputer(); myNewQueue->GetAllPublicQueues(); myNewQueue->GetPublicQueuesByCriteria(); myNewQueue->GetPrivateQueues(); return 0; }
Available since 1.1