This documentation is archived and is not being maintained.

MessageQueue.Send Method (Object, String, MessageQueueTransaction)

.NET Framework 1.1

Sends an object to the transactional queue referenced by this MessageQueue and specifies a label for the message.

[Visual Basic]
Overloads Public Sub Send( _
   ByVal obj As Object, _
   ByVal label As String, _
   ByVal transaction As MessageQueueTransaction _
public void Send(
 object obj,
 string label,
 MessageQueueTransaction transaction
public: void Send(
 Object* obj,
 String* label,
 MessageQueueTransaction* transaction
public function Send(
   obj : Object,
 label : String,
 transaction : MessageQueueTransaction


The object to send to the queue.
The label of the message.
The MessageQueueTransaction object.


Exception Type Condition
ArgumentNullException The label parameter is a null reference (Nothing in Visual Basic).


The transaction parameter is a null reference (Nothing).

MessageQueueException The Path property has not been set.


The Message Queuing application indicated an incorrect transaction usage.


An error occurred when accessing a Message Queuing API.


Use this overload to send a message containing the obj parameter to the transactional queue referenced by the MessageQueue, using an internal transaction context defined by the transaction parameter. With this overload, you can specify the string label that identifies the message. The object you send to the queue can be a Message, a structure, a data object, or any managed object. If you send any object other than a Message, the object is serialized and inserted into the body of the message.

Note   The message label is distinct from the message queue label, but both are application-dependent and have no inherit meaning to Message Queuing.

If you use this overload to send a message to a nontransactional queue, the message might be sent to the dead-letter queue without throwing an exception.

If you do not set the Formatter property before calling Send, the formatter defaults to the XmlMessageFormatter.

The DefaultPropertiesToSend property applies to any object other than a Message. If you specify, for example, a label or a priority using the DefaultPropertiesToSend member, these values apply to any message that contains an object that is not of type Message when your application sends it to the queue. When sending a Message, the property values set for the Message take precedence over DefaultPropertiesToSend, and the message's Message.Formatter property takes precedence over the queue's MessageQueue.Formatter property

[Visual Basic] Note    MessageQueueTransaction is threading apartment aware, so if your apartment state is STA, you cannot use the transaction in multiple threads. Visual Basic sets the state of the main thread to STA, so you must apply the MTAThreadAttribute in the Main subroutine. Otherwise, sending a transactional message using another thread throws a MessageQueueException exception. You apply the MTAThreadAttribute by using the following fragment.
[Visual Basic] 
public sub Main()

The following table shows whether this method is available in various Workgroup modes.

Workgroup Mode Available
Local computer Yes
Local computer + direct format name Yes
Remote computer No
Remote computer + direct format name Yes


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue.Send Overload List | DefaultPropertiesToSend | Message | MessageQueueTransaction | Transactional | Label | Peek | Receive | BeginPeek | BeginReceive