Export (0) Print
Expand All

MessageQueueTransaction Class

Provides a Message Queuing internal transaction.

System.Object
  System.Messaging.MessageQueueTransaction

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

public class MessageQueueTransaction : IDisposable

The MessageQueueTransaction type exposes the following members.

  NameDescription
Public methodMessageQueueTransactionInitializes a new instance of the MessageQueueTransaction class.
Top

  NameDescription
Public propertyStatusGets the status of the transaction.
Top

  NameDescription
Public methodAbortRolls back the pending internal transaction.
Public methodBeginBegins a new Message Queuing internal transaction.
Public methodCommitCommits a pending internal transaction.
Public methodDispose()Releases all resources used by the MessageQueueTransaction.
Protected methodDispose(Boolean)Releases the unmanaged resources used by the MessageQueueTransaction and optionally releases the managed resources.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeInfrastructure. Releases the resources held by the current instance. (Overrides Object.Finalize().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

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 committed. 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 non-transactional queue or receive a message from a non-transactional queue, the method throws an exception that indicates "Wrong Transaction Usage."

[Visual Basic]

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.

<System.MTAThreadAttribute>
 public sub Main()

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

This type is thread safe.

Show:
© 2014 Microsoft