MessageQueue::Send Method (Object^, String^, MessageQueueTransactionType)
Sends an object to the queue referenced by this MessageQueue and specifies a label for the message.
Assembly: System.Messaging (in System.Messaging.dll)
public: void Send( Object^ obj, String^ label, MessageQueueTransactionType transactionType )
Parameters
- obj
-
Type:
System::Object^
The object to send to the queue.
- label
-
Type:
System::String^
The label of the message.
- transactionType
-
Type:
System.Messaging::MessageQueueTransactionType
One of the MessageQueueTransactionType values, describing the type of transaction context to associate with the message.
| Exception | Condition |
|---|---|
| ArgumentNullException | The label parameter is null. |
| MessageQueueTransaction | The Message Queuing application indicated an incorrect transaction usage. |
| InvalidEnumArgumentException | The transactionType parameter is not one of the MessageQueueTransactionType members. |
| MessageQueueException |
Use this overload to send a message that contains the obj parameter to the queue referenced by the MessageQueue, using a transaction context defined by the transactionType parameter. Specify Automatic for the transactionType parameter if there is already an external transaction context attached to the thread that you want to use to send the message. Specify Single if you want to send the message as a single internal transaction. You can specify None if you want to send a transactional message to a non-transactional thread.
The object you send to the queue can be a Message 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. With this overload, you can specify the string label that identifies the message.
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 do not set the Formatter property before calling Send(Object^), 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.
The following table shows whether this method is available in various Workgroup modes.
Workgroup mode | Available |
|---|---|
Local computer | Yes |
Local computer and direct format name | Yes |
Remote computer | No |
Remote computer and direct format name | Yes |
The following code example demonstrates the use of Send(Object^, String^, MessageQueueTransactionType).
// Connect to a transactional queue on the local computer. MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue"); // Create a new message. Message^ msg = gcnew Message("Example Message Body"); // Send the message. queue->Send(msg, "Example Message Label", MessageQueueTransactionType::Single); queue->Close();
Available since 1.1