This documentation is archived and is not being maintained.

MessageQueueTransaction Class

Provides a Message Queuing internal transaction.

For a list of all members of this type, see MessageQueueTransaction Members.


[Visual Basic]
Public Class MessageQueueTransaction
   Implements IDisposable
public class MessageQueueTransaction : IDisposable
public __gc class MessageQueueTransaction : public IDisposable
public class MessageQueueTransaction implements IDisposable

Thread Safety

This type is safe for multithreaded operations.


To send or receive a message as part of a transaction, you can use the MessageQueueTransaction class to create a transaction and pass it to an overload of the MessageQueue.Send method or the MessageQueue.Receive method that takes a transaction parameter. Messages sent as part of a transaction must be sent to transactional queues. Messages received from transactional queues must be received using a specified transaction.

Note   In addition to the Receive method, you can receive messages with a specified identifier or specified correlation identifier. See the ReceiveById and ReceiveByCorrelationId methods for more information about selectively receiving messages from transactional queues.

Messages sent to transactional queues are removed if the transaction is rolled back. Similarly, messages received from transactional queues are returned to the queue if the transaction is rolled back.

If you instantiate a MessageQueueTransaction and pass it to an applicable overload of the Send method or Receive method to send a message to a nontransactional queue or receive a message from a nontransational queue, the method throws an exception indicating "Wrong Transaction Usage."

[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()


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

MessageQueueTransaction Members | System.Messaging Namespace | MessageQueue.Transactional | MessageQueue.Send