DefaultPropertiesToSend Class
Specifies the default property values that will be used when sending objects other than Message instances to a message queue.
For a list of all members of this type, see DefaultPropertiesToSend Members.
System.Object
System.Messaging.DefaultPropertiesToSend
[Visual Basic] Public Class DefaultPropertiesToSend [C#] public class DefaultPropertiesToSend [C++] public __gc class DefaultPropertiesToSend [JScript] public class DefaultPropertiesToSend
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
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.
Example
[Visual Basic, C#, C++] The following example uses the priority of a message to determine default properties to send for the message.
[Visual Basic] 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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Messaging
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Messaging (in System.Messaging.dll)
See Also
DefaultPropertiesToSend Members | System.Messaging Namespace | Message | MessageQueue.DefaultPropertiesToSend