DefaultPropertiesToSend Class
Specifies the default property values that will be used when sending objects other than Message instances to a message queue.
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
#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;
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.