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 提供許多方法,可讓您篩選網路上的公用佇列搜尋。 依佇列標籤、類別或伺服器位置篩選的特定方法為 GetPublicQueuesByLabelGetPublicQueuesByCategoryGetPublicQueuesByMachine

類別 MessageQueueCriteria 搭配 方法使用 GetPublicQueues 時,可讓您精簡篩選準則。 您可以指定未透過其中一個 * 方法或多個準則特別定址的 GetPublicQueuesBy 搜尋準則。 您可以將 實例傳遞 MessageQueueCriteriaGetPublicQueues 方法,以便藉由佇列建立或修改時間、佇列所在的電腦、佇列標籤或類別,或這些屬性的任何組合來搜尋。

依多個屬性篩選時,準則是由將 運算子套用 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)

適用於

另請參閱