MessageQueueCriteria 类

定义

当执行查询时使用 MessageQueue 类的 GetPublicQueues() 方法筛选消息队列。

public ref class MessageQueueCriteria
public class MessageQueueCriteria
type MessageQueueCriteria = class
Public Class MessageQueueCriteria
继承
MessageQueueCriteria

示例

以下示例循环访问消息队列,并显示在最后一天创建且存在于计算机“MyComputer”中的每个队列的路径。

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   // 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". 
   void ListPublicQueuesByCriteria()
   {
      UInt32 numberQueues = 0;
      
      // Specify the criteria to filter by.
      MessageQueueCriteria^ myCriteria = gcnew MessageQueueCriteria;
      myCriteria->MachineName = "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( "No public queues match criteria." );
      }

      return;
   }

};

int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   
   // Output the count of Lowest priority messages.
   myNewQueue->ListPublicQueuesByCriteria();
   return 0;
}
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;
        }
    }
}
Imports System.Messaging

 
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


        
        ' 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

End Class

注解

MessageQueue 类提供了许多方法,可用于筛选网络上的公共队列的搜索。 按队列标签、类别或服务器位置 GetPublicQueuesByLabel进行筛选的特定方法是, GetPublicQueuesByCategory以及 GetPublicQueuesByMachine

MessageQueueCriteria 与方法一起使用 GetPublicQueues 时,允许优化筛选器。 可以指定搜索条件,这些条件不是通过 *方法之 GetPublicQueuesBy一或多个条件专门解决的。 可以将实例GetPublicQueues传递到MessageQueueCriteria方法中,以便通过队列创建或修改时间、队列所在的计算机、队列标签或类别或这些属性的任意组合进行搜索。

按多个属性进行筛选时,条件由将 AND 运算符应用于属性集组成。 因此,当为 CreatedAfter 属性指定值以及 MachineName 该属性时,需要请求在指定时间之后创建且驻留在特定计算机上的所有队列。

设置任何属性时,设置该属性的方法还会设置一个标志,以指示它应包含在要生成的筛选器中。 无法从搜索筛选器中删除单个属性。 而是通过调用 ClearAll从筛选器中删除所有属性,然后设置要构建到搜索筛选器中的属性。 ClearAll 将所有属性重置为“未设置”默认状态。

在尝试读取属性之前,必须设置属性;否则,将引发异常。

构造函数

MessageQueueCriteria()

初始化 MessageQueueCriteria 类的新实例。

属性

Category

获取或设置作为网络中队列的筛选依据的类别。

CreatedAfter

获取或设置队列创建日期和时间的下限,以此作为筛选网络上的队列的依据。

CreatedBefore

获取或设置队列创建日期和时间的上限,以此作为筛选网络上的队列的依据。

Label

获取或设置作为网络中队列的筛选依据的标签。

MachineName

获取或设置作为网络中队列的筛选依据的计算机名。

ModifiedAfter

获取或设置队列修改日期和时间的下限,以此作为筛选网络上的队列的依据。

ModifiedBefore

获取或设置队列修改日期和时间的上限,以此作为筛选网络上的队列的依据。

方法

ClearAll()

清除置入筛选器的所有属性,并将所有属性值设为“未设置”状态。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅