MessageQueueTransaction 类

定义

提供消息队列内部事务。Provides a Message Queuing internal transaction.

public ref class MessageQueueTransaction : IDisposable
public class MessageQueueTransaction : IDisposable
type MessageQueueTransaction = class
    interface IDisposable
Public Class MessageQueueTransaction
Implements IDisposable
继承
MessageQueueTransaction
实现

注解

若要在事务中发送或接收MessageQueueTransaction消息, 可以使用类创建事务, 并将其传递给MessageQueue.Send方法的重载或MessageQueue.Receive采用transaction参数的方法。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.

除了Receive方法之外, 还可以接收具有指定标识符或指定相关标识符的消息。In addition to the Receive method, you can receive messages with a specified identifier or specified correlation identifier. 有关有选择ReceiveByCorrelationId地接收来自事务性队列的消息的详细信息,请参阅和方法。ReceiveByIdSee 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.

如果实例化MessageQueueTransaction并将其传递到Send方法或Receive方法的适用重载, 以将消息发送到非事务性队列或从非事务性队列接收消息, 则该方法将引发异常,指示 "事务使用错误"。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."

MessageQueueTransaction线程单元感知, 因此, 如果单元状态为STA, 则不能在多个线程中使用事务。MessageQueueTransaction is threading apartment aware, so if your apartment state is STA, you cannot use the transaction in multiple threads. Visual Basic 将主线程的状态设置为STA, 因此你必须MTAThreadAttributeMain子例程中应用。Visual Basic sets the state of the main thread to STA, so you must apply the MTAThreadAttribute in the Main subroutine. 否则,利用另一个线程发送事务性消息将引发 MessageQueueException 异常。Otherwise, sending a transactional message using another thread throws a MessageQueueException exception. 使用以下片段MTAThreadAttribute应用。You apply the MTAThreadAttribute by using the following fragment.

<System.MTAThreadAttribute>  
 public sub Main()  

构造函数

MessageQueueTransaction()

初始化 MessageQueueTransaction 类的新实例。Initializes a new instance of the MessageQueueTransaction class.

属性

Status

获取事务的状态。Gets the status of the transaction.

方法

Abort()

回滚正挂起的内部事务。Rolls back the pending internal transaction.

Begin()

开始新的消息队列内部事务。Begins a new Message Queuing internal transaction.

Commit()

提交正挂起的内部事务。Commits a pending internal transaction.

Dispose()

释放由 MessageQueueTransaction 使用的所有资源。Releases all resources used by the MessageQueueTransaction.

Dispose(Boolean)

释放由 MessageQueueTransaction 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the MessageQueueTransaction and optionally releases the managed resources.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
Finalize()

释放由当前实例所持有的资源。Releases the resources held by the current instance.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

线程安全性

此类型是线程安全的。This type is thread safe.

另请参阅