This topic has not yet been rated - Rate this topic

MessageQueueCriteria Class

Filters message queues when performing a query using the MessageQueue class's GetPublicQueues method.

System.Object
  System.Messaging.MessageQueueCriteria

Namespace:  System.Messaging
Assembly:  System.Messaging (in System.Messaging.dll)
public class MessageQueueCriteria

The MessageQueueCriteria type exposes the following members.

  NameDescription
Public methodMessageQueueCriteriaInitializes a new instance of the MessageQueueCriteria class.
Top
  NameDescription
Public propertyCategoryGets or sets the category by which to filter queues in the network.
Public propertyCreatedAfterGets or sets the lower boundary of the queue creation date and time by which to filter queues on the network.
Public propertyCreatedBeforeGets or sets the upper boundary of the queue creation date and time by which to filter queues on the network.
Public propertyLabelGets or sets the label by which to filter queues in the network.
Public propertyMachineNameGets or sets the computer name by which to filter queues in the network.
Public propertyModifiedAfterGets or sets the lower boundary of the queue modification date and time by which to filter queues on the network.
Public propertyModifiedBeforeGets or sets the upper boundary of the queue modification date and time by which to filter queues on the network.
Top
  NameDescription
Public methodClearAllClears all properties from being built into a filter and puts all property values into a "not set" state.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The MessageQueue class provides a number of methods that enable you to filter your search for public queues on the network. Specific methods for filtering by queue label, category, or server location are the GetPublicQueuesByLabel, GetPublicQueuesByCategory, and GetPublicQueuesByMachine.

The MessageQueueCriteria class, when used with the GetPublicQueues method, allows you to refine your filter. You can specify search criteria not specifically addressed through one of the GetPublicQueuesBy* methods, or by multiple criteria. You can pass a MessageQueueCriteria instance into the GetPublicQueues method in order to search, for example, by queue creation or modification times, the computer the queue resides on, the queue label or category, or any combination of these properties.

When filtering by multiple properties, the criteria are composed by applying the AND operator to the set of properties. Thus, when you specify a value for the CreatedAfter property together with the MachineName property, you are asking for all queues that were created after a specified time and that reside on a specific computer.

When you set any property, the method that sets the property also sets a flag to indicate that it should be included in the filter you are building. You cannot remove individual properties from the search filter. Instead, you remove all properties from the filter by calling ClearAll, and then set the properties that you do want to build into the search filter. ClearAll resets all properties into a "not set" default state.

You must set a property before trying to read it; otherwise, an exception is thrown.

The following example 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".

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;
		}
	}
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.