次の方法で共有


DefaultPropertiesToSend クラス

Message インスタンス以外のオブジェクトをメッセージ キューに送信するときに使われるプロパティの既定値を指定します。

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

System.Object
   System.Messaging.DefaultPropertiesToSend

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

スレッドセーフ

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

解説

MessageQueue に送信されるメッセージ用に選択されるプロパティの既定値を設定できます。 DefaultPropertiesToSend は、 Message インスタンス以外のオブジェクトがキューに送信されるときに、送信されるメッセージのプロパティの既定値を指定するために使用されます。たとえば、コード myMessageQueue.Send("hello")Send メソッドに渡される文字列引数などです。 Message クラスには、 DefaultPropertiesToSend 内のプロパティに対応する同じ名前のプロパティがあります。前者のプロパティは Message インスタンスを送信するときに値を提供します。キューの MessageQueue.DefaultPropertiesToSend を指定していても、そのキューに Message オブジェクトを送信すると、キューの DefaultPropertiesToSend の値は、同じ名前の Message プロパティの値によってオーバーライドされます。

明示的に設定しないプロパティは、コントラクタ DefaultPropertiesToSend によって指定される既定値に設定されます。

DefaultPropertiesToSend のインスタンスの初期プロパティ値の一覧については、 DefaultPropertiesToSend コンストラクタのトピックを参照してください。

使用例

[Visual Basic, C#, C++] メッセージの優先順位を使用して、メッセージを送信するときの既定のプロパティを決定する例を次に示します。

 
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 specifies different types of default
        ' properties for messages.
        '**************************************************

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Send normal and high priority messages.
            myNewQueue.SendNormalPriorityMessages()
            myNewQueue.SendHighPriorityMessages()

            Return

        End Sub 'Main


        '**************************************************
        ' Associates selected message property values
        ' with high priority messages.
        '**************************************************

        Public Sub SendHighPriorityMessages()

            ' Connect to a message queue.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Associate selected default property values with high
            ' priority messages.
            myQueue.DefaultPropertiesToSend.Priority = _
                MessagePriority.High
            myQueue.DefaultPropertiesToSend.Label = _
                "High Priority Message"
            myQueue.DefaultPropertiesToSend.Recoverable = True
            myQueue.DefaultPropertiesToSend.TimeToReachQueue = _
                New TimeSpan(0, 0, 30)

            ' Send messages using these defaults.
            myQueue.Send("High priority message data 1.")
            myQueue.Send("High priority message data 2.")
            myQueue.Send("High priority message data 3.")

            Return

        End Sub 'SendHighPriorityMessages


        '**************************************************
        ' Associates selected message property values
        ' with normal priority messages.
        '**************************************************

        Public Sub SendNormalPriorityMessages()

            ' Connect to a message queue.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Associate selected default property values with normal
            ' priority messages.
            myQueue.DefaultPropertiesToSend.Priority = _
                MessagePriority.Normal
            myQueue.DefaultPropertiesToSend.Label = _
                "Normal Priority Message"
            myQueue.DefaultPropertiesToSend.Recoverable = False
            myQueue.DefaultPropertiesToSend.TimeToReachQueue = _
                New TimeSpan(0, 2, 0)

            ' Send messages using these defaults.
            myQueue.Send("Normal priority message data 1.")
            myQueue.Send("Normal priority message data 2.")
            myQueue.Send("Normal priority message data 3.")

            Return

        End Sub 'SendNormalPriorityMessages

    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 specifies different types of default
        // properties for messages.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Send normal and high priority messages.
            myNewQueue.SendNormalPriorityMessages();
            myNewQueue.SendHighPriorityMessages();
                        
            return;
        }


        //**************************************************
        // Associates selected message property values
        // with high priority messages.
        //**************************************************
        
        public void SendHighPriorityMessages()
        {

            // Connect to a message queue.
            MessageQueue myQueue = new 
                MessageQueue(".\\myQueue");

            // Associate selected default property values with high
            // priority messages.
            myQueue.DefaultPropertiesToSend.Priority = 
                MessagePriority.High;
            myQueue.DefaultPropertiesToSend.Label = 
                "High Priority Message";
            myQueue.DefaultPropertiesToSend.Recoverable = true;
            myQueue.DefaultPropertiesToSend.TimeToReachQueue =
                new TimeSpan(0,0,30);
            
            // Send messages using these defaults.
            myQueue.Send("High priority message data 1.");
            myQueue.Send("High priority message data 2.");
            myQueue.Send("High priority message data 3.");
            
            return;
        }


        //**************************************************
        // Associates selected message property values
        // with normal priority messages.
        //**************************************************
        
        public void SendNormalPriorityMessages()
        {

            // Connect to a message queue.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Associate selected default property values with normal
            // priority messages.
            myQueue.DefaultPropertiesToSend.Priority = 
                MessagePriority.Normal;
            myQueue.DefaultPropertiesToSend.Label = 
                "Normal Priority Message";
            myQueue.DefaultPropertiesToSend.Recoverable = false;
            myQueue.DefaultPropertiesToSend.TimeToReachQueue =
                new TimeSpan(0,2,0);
            
            // Send messages using these defaults.
            myQueue.Send("Normal priority message data 1.");
            myQueue.Send("Normal priority message data 2.");
            myQueue.Send("Normal priority message data 3.");
            
            return;
        }
    }
}

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

using namespace System;
using namespace System::Messaging;

__gc class MyNewQueue 
{
public:
    // Associates selected message property values
    // with high priority messages.
    void SendHighPriorityMessages() 
    {
        // Connect to a message queue.
        MessageQueue* myQueue = new MessageQueue(S".\\myQueue");

        // Associate selected default property values with high
        // priority messages.
        myQueue->DefaultPropertiesToSend->Priority = MessagePriority::High;
        myQueue->DefaultPropertiesToSend->Label = S"High Priority Message";
        myQueue->DefaultPropertiesToSend->Recoverable = true;
        myQueue->DefaultPropertiesToSend->TimeToReachQueue = TimeSpan(0, 0, 30);

        // Send messages using these defaults.
        myQueue->Send(S"High priority message data 1.");
        myQueue->Send(S"High priority message data 2.");
        myQueue->Send(S"High priority message data 3.");

        return;
    }

    // Associates selected message property values
    // with normal priority messages.
    void SendNormalPriorityMessages() 
    {
        // Connect to a message queue.
        MessageQueue* myQueue = new MessageQueue(S".\\myQueue");

        // Associate selected default property values with normal
        // priority messages.
        myQueue->DefaultPropertiesToSend->Priority = MessagePriority::Normal;
        myQueue->DefaultPropertiesToSend->Label = S"Normal Priority Message";
        myQueue->DefaultPropertiesToSend->Recoverable = false;
        myQueue->DefaultPropertiesToSend->TimeToReachQueue = TimeSpan(0, 2, 0);

        // Send messages using these defaults.
        myQueue->Send(S"Normal priority message data 1.");
        myQueue->Send(S"Normal priority message data 2.");
        myQueue->Send(S"Normal priority message data 3.");

        return;
    }
};

// Provides an entry point into the application.
// This example specifies different types of default
// properties for messages.
int main() 
{
    // Create a new instance of the class.
    MyNewQueue* myNewQueue = new MyNewQueue();

    // Send normal and high priority messages.
    myNewQueue->SendNormalPriorityMessages();
    myNewQueue->SendHighPriorityMessages();

    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 内)

参照

DefaultPropertiesToSend メンバ | System.Messaging 名前空間 | Message | MessageQueue.DefaultPropertiesToSend