Export (0) Print
Expand All

MessageQueue.GetPublicQueuesByLabel Method

Retrieves all the public queues on the network that carry the specified label.

Namespace: System.Messaging
Assembly: System.Messaging (in system.messaging.dll)

public static MessageQueue[] GetPublicQueuesByLabel (
	string label
)
public static MessageQueue[] GetPublicQueuesByLabel (
	String label
)
public static function GetPublicQueuesByLabel (
	label : String
) : MessageQueue[]
Not applicable.

Parameters

label

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

Return Value

An array of MessageQueue objects that reference the retrieved public queues.

Exception typeCondition

MessageQueueException

An error occurred when accessing a Message Queuing method.

ArgumentNullException

The label parameter is a null reference (Nothing in Visual Basic).

Use this method to filter the public queues by label.

GetPublicQueuesByLabel retrieves a static snapshot of the queues. To interact with a dynamic list of the queues, use GetMessageQueueEnumerator. You can specify the label 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;
		}
	}
}

package MyProject;

import System.*;
import System.Messaging.*;

/// <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(String[] args)
    {
        // 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;
    } //main

    //**************************************************
    // 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.
        for (int iCtr = 0; iCtr < queueList.length; iCtr++) {
            MessageQueue queueItem = queueList[iCtr];
            queueItem.Send("Broadcast message.");
        }

        return;
    } //GetQueuesByCategory

    //**************************************************
    // 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.
        for (int iCtr = 0; iCtr < queueList.length; iCtr++) {
            MessageQueue queueItem = queueList[iCtr];
            queueItem.Send("Broadcast message.");
        }

        return;
    } //GetQueuesByLabel

    //**************************************************
    // 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.
        for (int iCtr = 0; iCtr < queueList.length; iCtr++) {
            MessageQueue queueItem = queueList[iCtr];
            Console.WriteLine(queueItem.get_Path());
        }

        return;
    } //GetQueuesByComputer

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

        return;
    } //GetAllPublicQueues

    //**************************************************
    // 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.set_CreatedAfter(DateTime.get_Now().Subtract(
            new TimeSpan(1, 0, 0, 0)));
        myCriteria.set_ModifiedBefore(DateTime.get_Now());
        myCriteria.set_MachineName(".");
        myCriteria.set_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.
        for (int iCtr = 0; iCtr < queueList.length; iCtr++) {
            MessageQueue queueItem = queueList[iCtr];
            Console.WriteLine(queueItem.get_Path());
        }

        return;
    } //GetPublicQueuesByCriteria

    //**************************************************
    // 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.
        for (int iCtr = 0; iCtr < queueList.length; iCtr++) {
            MessageQueue queueItem = queueList[iCtr];
            Console.WriteLine(queueItem.get_Path());
        }

        return;
    } //GetPrivateQueues
} //MyNewQueue

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft