次の方法で共有


MessageQueueCriteria クラス

MessageQueue クラスの GetPublicQueues メソッドを使用してクエリを実行するときに、メッセージ キューにフィルタをかけます。

この型のすべてのメンバの一覧については、MessageQueueCriteria メンバ を参照してください。

System.Object
   System.Messaging.MessageQueueCriteria

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

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

MessageQueue クラスには、ネットワーク上のパブリック キューの検索結果にフィルタをかける多くのメソッドがあります。キューのラベル、カテゴリ、またはサーバーの場所でフィルタをかけるメソッドは、 GetPublicQueuesByLabelGetPublicQueuesByCategory 、および GetPublicQueuesByMachine です。

GetPublicQueues メソッドで MessageQueueCriteria クラスを使用すると、フィルタを詳細に指定できます。 GetPublicQueuesBy... メソッドでは処理できない検索条件や、複数の基準を指定できます。たとえば、キューの作成時刻または変更時刻、キューが存在するコンピュータ、キューのラベルまたはカテゴリ、またはこれらのプロパティの任意の組み合わせで検索するには、 MessageQueueCriteria インスタンスを GetPublicQueues メソッドに渡します。

複数のプロパティでフィルタ処理をする場合は、プロパティのセットに AND 演算子を適用することによって、基準が作成されます。そのため、 CreatedAfter プロパティと MachineName プロパティに値を指定すると、指定した時刻よりも後に作成された特定のコンピュータに存在するすべてのキューを問い合わせることになります。

プロパティを設定するときに、プロパティを設定するメソッドは、構築するフィルタにそのプロパティを含める必要があることを示すフラグも設定します。検索フィルタから、それぞれのプロパティを削除することはできません。 ClearAll を呼び出して、すべてのプロパティをフィルタから削除した後で、検索フィルタに構築するプロパティを設定します。 ClearAll は、すべてのプロパティを既定の "設定なし" の状態にリセットします。

メモ   プロパティは、読み取りを試行する前に設定する必要があります。アプリケーションが設定していないプロパティを読み取ると、例外がスローされます。

使用例

[Visual Basic, C#, C++] 一連のメッセージ キューを反復処理し、1 日前に作成され、"MyComputer" という名前のコンピュータ上に存在するキューのパスを表示する例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Messaging

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Messaging (System.Messaging.dll 内)

参照

MessageQueueCriteria メンバ | System.Messaging 名前空間 | GetPublicQueues | GetPublicQueuesByMachine | GetPublicQueuesByLabel | GetPublicQueuesByCategory