Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MessageQueue.GetPublicQueuesByCategory Method

Retrieves all the public queues on the network that belong to the specified category.

Namespace:  System.Messaging
Assembly:  System.Messaging (in System.Messaging.dll)
public static MessageQueue[] GetPublicQueuesByCategory(
	Guid category
)

Parameters

category
Type: System.Guid

A Guid that groups the set of queues to be retrieved.

Return Value

Type: System.Messaging.MessageQueue[]
An array of MessageQueue objects that reference the retrieved public queues.
ExceptionCondition
MessageQueueException

An error occurred when accessing a Message Queuing method.

Use this method to filter the public queues by category. The Category property provides access to the Message Queuing type ID property (which is read/write) of a particular queue. Although you can use NewGuid to create a category value that is unique across all Guid values, it is not necessary. The category value needs to be distinct only from other categories, not from all other Guid values. For example, you can assign {00000000-0000-0000-0000-000000000001} as the Category for one set of queues and {00000000-0000-0000-0000-000000000002} as the Category for another set.

GetPublicQueuesByCategory(Guid) retrieves a static snapshot of the queues. To interact with a dynamic list of the queues, use GetMessageQueueEnumerator. You can specify the category as part of the MessageQueueCriteria you pass into the method.

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;
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 gets lists of queues by a variety 
		// of criteria. 
		//************************************************** 

		public static void Main()
		{
			// Create a new instance of the class.
			MyNewQueue myNewQueue = new MyNewQueue();

			// Send normal and high priority messages.
			myNewQueue.GetQueuesByCategory();
			myNewQueue.GetQueuesByLabel();
			myNewQueue.GetQueuesByComputer();
			myNewQueue.GetAllPublicQueues();
			myNewQueue.GetPublicQueuesByCriteria();
			myNewQueue.GetPrivateQueues();
						
			return;
		}


		//************************************************** 
		// Gets a list of queues with a specified category. 
		// Sends a broadcast message to all queues in that 
		// category. 
		//************************************************** 
		
		public void GetQueuesByCategory()
		{
			// Get a list of queues with the specified category.
			MessageQueue[] QueueList = 
				MessageQueue.GetPublicQueuesByCategory(new 
				Guid("{00000000-0000-0000-0000-000000000001}"));

			// Send a broadcast message to each queue in the array. 
			foreach(MessageQueue queueItem in QueueList)
			{
				queueItem.Send("Broadcast message.");
			}
			
			return;
		}


		//************************************************** 
		// Gets a list of queues with a specified label. 
		// Sends a broadcast message to all queues with that 
		// label. 
		//************************************************** 
		
		public void GetQueuesByLabel()
		{
			// Get a list of queues with the specified label.
			MessageQueue[] QueueList = 
				MessageQueue.GetPublicQueuesByLabel("My Label");

			// Send a broadcast message to each queue in the array. 
			foreach(MessageQueue queueItem in QueueList)
			{
				queueItem.Send("Broadcast message.");
			}
			
			return;
		}


		//************************************************** 
		// Gets a list of queues on a specified computer.  
		// Displays the list on screen. 
		//************************************************** 
		
		public void GetQueuesByComputer()
		{
			// Get a list of queues on the specified computer.
			MessageQueue[] QueueList = 
				MessageQueue.GetPublicQueuesByMachine("MyComputer");

			// Display the paths of the queues in the list. 
			foreach(MessageQueue queueItem in QueueList)
			{
				Console.WriteLine(queueItem.Path);
			}

			return;
		}


		//************************************************** 
		// Gets a list of all public queues. 
		//************************************************** 
		
		public void GetAllPublicQueues()
		{
			// Get a list of public queues.
			MessageQueue[] QueueList = 
				MessageQueue.GetPublicQueues();
	
			return;
		}


		//************************************************** 
		// Gets a list of all public queues that match  
		// specified criteria. Displays the list on  
		// screen. 
		//************************************************** 
		
		public void GetPublicQueuesByCriteria()
		{
			// Define criteria to filter the queues.
			MessageQueueCriteria myCriteria = new 
				MessageQueueCriteria();
			myCriteria.CreatedAfter = DateTime.Now.Subtract(new 
				TimeSpan(1,0,0,0));
			myCriteria.ModifiedBefore = DateTime.Now;
			myCriteria.MachineName = ".";
			myCriteria.Label = "My Queue";
			
			// Get a list of queues with that criteria.
			MessageQueue[] QueueList = 
				MessageQueue.GetPublicQueues(myCriteria);

			// Display the paths of the queues in the list. 
			foreach(MessageQueue queueItem in QueueList)
			{
				Console.WriteLine(queueItem.Path);
			}

			return;
		}


		//************************************************** 
		// Gets a list of private queues on the local  
		// computer. Displays the list on screen. 
		//************************************************** 
		
		public void GetPrivateQueues()
		{
			// Get a list of queues with the specified category.
			MessageQueue[] QueueList = 
				MessageQueue.GetPrivateQueuesByMachine(".");

			// Display the paths of the queues in the list. 
			foreach(MessageQueue queueItem in QueueList)
			{
				Console.WriteLine(queueItem.Path);
			}
			
			return;
		}
	}
}
#using <mscorlib.dll>
#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
using namespace System::Collections;

__gc class MyNewQueue 
{
	// Gets a list of queues with a specified category.
	// Sends a broadcast message to all queues in that
	// category.
public:
	void GetQueuesByCategory() 
	{
		// Get a list of queues with the specified category.
		MessageQueue* QueueList[] = 
			MessageQueue::GetPublicQueuesByCategory( 
			Guid(S" {00000000-0000-0000-0000-000000000001}"));

		// Send a broadcast message to each queue in the array.
		IEnumerator* myEnum = QueueList->GetEnumerator();
		while (myEnum->MoveNext()) 
		{
			MessageQueue* queueItem = __try_cast<MessageQueue*>(myEnum->Current);
			queueItem->Send(S"Broadcast message.");
		}
		return;
	}

	// Gets a list of queues with a specified label.
	// Sends a broadcast message to all queues with that
	// label.
public:
	void GetQueuesByLabel() 
	{
		// Get a list of queues with the specified label.
		MessageQueue* QueueList[] = 
			MessageQueue::GetPublicQueuesByLabel(S"My Label");

		// Send a broadcast message to each queue in the array.
		IEnumerator* myEnum = QueueList->GetEnumerator();
		while (myEnum->MoveNext()) 
		{
			MessageQueue* queueItem = __try_cast<MessageQueue*>(myEnum->Current);

			queueItem->Send(S"Broadcast message.");
		}

		return;
	}

	// Gets a list of queues on a specified computer. 
	// Displays the list on screen.
public:
	void GetQueuesByComputer() 
	{
		// Get a list of queues on the specified computer.
		MessageQueue* QueueList[] = 
			MessageQueue::GetPublicQueuesByMachine(S"MyComputer");

		// Display the paths of the queues in the list.
		IEnumerator* myEnum = QueueList->GetEnumerator();
		while (myEnum->MoveNext()) 
		{
			MessageQueue* queueItem = __try_cast<MessageQueue*>(myEnum->Current);

			Console::WriteLine(queueItem->Path);
		}

		return;
	}

	// Gets a list of all public queues.
public:
	void GetAllPublicQueues() 
	{
		// Get a list of public queues.
		MessageQueue* QueueList[] = MessageQueue::GetPublicQueues();

		return;
	}


	// Gets a list of all public queues that match 
	// specified criteria. Displays the list on 
	// screen.
public:
	void GetPublicQueuesByCriteria() 
	{
		// Define criteria to filter the queues.
		MessageQueueCriteria* myCriteria = new MessageQueueCriteria();
		myCriteria->CreatedAfter = DateTime::Now.Subtract(TimeSpan(1, 0, 0, 0));
		myCriteria->ModifiedBefore = DateTime::Now;
		myCriteria->MachineName = S".";
		myCriteria->Label = S"My Queue";

		// Get a list of queues with that criteria.
		MessageQueue* QueueList[] = 
			MessageQueue::GetPublicQueues(myCriteria);

		// Display the paths of the queues in the list.
		IEnumerator* myEnum = QueueList->GetEnumerator();
		while (myEnum->MoveNext()) 
		{
			MessageQueue* queueItem = __try_cast<MessageQueue*>(myEnum->Current);

			Console::WriteLine(queueItem->Path);
		}

		return;
	}

	// Gets a list of private queues on the local 
	// computer. Displays the list on screen.
public:
	void GetPrivateQueues() 
	{
		// Get a list of queues with the specified category.
		MessageQueue* QueueList[] = 
			MessageQueue::GetPrivateQueuesByMachine(S".");

		// Display the paths of the queues in the list.
		IEnumerator* myEnum = QueueList->GetEnumerator();
		while (myEnum->MoveNext()) 
		{
			MessageQueue* queueItem = __try_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 = new MyNewQueue();

	// Send normal and high priority messages.
	myNewQueue->GetQueuesByCategory();
	myNewQueue->GetQueuesByLabel();
	myNewQueue->GetQueuesByComputer();
	myNewQueue->GetAllPublicQueues();
	myNewQueue->GetPublicQueuesByCriteria();
	myNewQueue->GetPrivateQueues();

	return 0;
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.