Export (0) Print
Expand All

MessageQueueCriteria Class

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

For a list of all members of this type, see MessageQueueCriteria Members.

System.Object
   System.Messaging.MessageQueueCriteria

[Visual Basic]
Public Class MessageQueueCriteria
[C#]
public class MessageQueueCriteria
[C++]
public __gc class MessageQueueCriteria
[JScript]
public class MessageQueueCriteria

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

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.

Note   You must set a property before trying to read it. Reading a property the application has not yet set throws an exception.

Example

[Visual Basic, C#, C++] 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".

[Visual Basic] 
Imports System
Imports 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 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 'Main


        '**************************************************
        ' 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 'ListPublicQueuesByCriteria

    End Class 'MyNewQueue
End Namespace 'MyProject

[C#] 
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;
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

__gc class MyNewQueue 
{
    // 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() 
    {
        UInt32 numberQueues = 0;

        // Specify the criteria to filter by.
        MessageQueueCriteria* myCriteria = new MessageQueueCriteria();
        myCriteria->MachineName = S"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(S"No public queues match criteria.");
        }

        return;
    }
};

int main() 
{
    // Create a new instance of the class.
    MyNewQueue* myNewQueue = new MyNewQueue();

    // Output the count of Lowest priority messages.
    myNewQueue->ListPublicQueuesByCriteria();

    return 0;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Messaging

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Messaging (in System.Messaging.dll)

See Also

MessageQueueCriteria Members | System.Messaging Namespace | GetPublicQueues | GetPublicQueuesByMachine | GetPublicQueuesByLabel | GetPublicQueuesByCategory

Show:
© 2015 Microsoft