DefaultPropertiesToSend Class
Assembly: System.Messaging (in system.messaging.dll)
You can set default values on selected properties for messages sent to a MessageQueue. DefaultPropertiesToSend is used to specify default property values of the message being sent when objects other than Message instances are sent to a queue, for example, the string argument passed into the Send method in the code fragment, myMessageQueue.Send("hello"). The Message class has corresponding, identically named properties to those in DefaultPropertiesToSend that provide the values when sending a Message instance specifically. Even if you have specified MessageQueue.DefaultPropertiesToSend for a queue, sending a Message object to that queue will cause the values for the identically named Message properties to override the queue's DefaultPropertiesToSend values.
Properties that you do not set explicitly default to the values specified by the constructor, DefaultPropertiesToSend.
For a list of initial property values for an instance of DefaultPropertiesToSend, see the DefaultPropertiesToSend constructor.
The following code example uses the priority of a message to determine default properties to send for the message.
Imports System Imports System.Messaging 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
package MyProject;
import System.*;
import System.Messaging.*;
/// <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(String[] args)
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Send normal and high priority messages.
myNewQueue.SendNormalPriorityMessages();
myNewQueue.SendHighPriorityMessages();
return;
} //main
//**************************************************
// 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.get_DefaultPropertiesToSend().
set_Priority(MessagePriority.High);
myQueue.get_DefaultPropertiesToSend().
set_Label("High Priority Message");
myQueue.get_DefaultPropertiesToSend().
set_Recoverable(true);
myQueue.get_DefaultPropertiesToSend().
set_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;
} //SendHighPriorityMessages
//**************************************************
// 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.get_DefaultPropertiesToSend().
set_Priority(MessagePriority.Normal);
myQueue.get_DefaultPropertiesToSend().
set_Label("Normal Priority Message");
myQueue.get_DefaultPropertiesToSend().
set_Recoverable(false);
myQueue.get_DefaultPropertiesToSend().
set_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;
} //SendNormalPriorityMessages
} //MyNewQueue
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.