MessageQueueTransaction MessageQueueTransaction MessageQueueTransaction MessageQueueTransaction Class

定義

提供訊息佇列內部交易。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
繼承
MessageQueueTransactionMessageQueueTransactionMessageQueueTransactionMessageQueueTransaction
實作

備註

若要在交易中傳送或接收訊息, 您可以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. 您可以使用下列片段來套用。MTAThreadAttributeYou apply the MTAThreadAttribute by using the following fragment.

<System.MTAThreadAttribute>  
 public sub Main()  

建構函式

MessageQueueTransaction() MessageQueueTransaction() MessageQueueTransaction() MessageQueueTransaction()

初始化 MessageQueueTransaction 類別的新執行個體。Initializes a new instance of the MessageQueueTransaction class.

屬性

Status Status Status Status

取得交易的狀態。Gets the status of the transaction.

方法

Abort() Abort() Abort() Abort()

復原暫止的內部交易。Rolls back the pending internal transaction.

Begin() Begin() Begin() Begin()

開始新的訊息佇列內部交易。Begins a new Message Queuing internal transaction.

Commit() Commit() Commit() Commit()

認可一個暫止的內部交易。Commits a pending internal transaction.

Dispose() Dispose() Dispose() Dispose()

釋放 MessageQueueTransaction 所使用的所有資源。Releases all resources used by the MessageQueueTransaction.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 MessageQueueTransaction 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the MessageQueueTransaction and optionally releases the managed resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

將目前執行個體所持有的資源釋出。Releases the resources held by the current instance.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

執行緒安全性

此型別具備執行緒安全。This type is thread safe.

另請參閱