This documentation is archived and is not being maintained.

DefaultPropertiesToSend Class

Specifies the default property values that will be used when sending objects other than Message instances to a message queue.

Namespace:  System.Messaging
Assembly:  System.Messaging (in System.Messaging.dll)

[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public class DefaultPropertiesToSend

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.

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;
		}
	}
}
#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;
}

System.Object
  System.Messaging.DefaultPropertiesToSend

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0
Show: