Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

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)

public class DefaultPropertiesToSend
public class DefaultPropertiesToSend
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;
		}
	}
}

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

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 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.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.