CommittableTransaction 類別

定義

描述可認可的交易。Describes a committable transaction.

public ref class CommittableTransaction sealed : System::Transactions::Transaction, IAsyncResult, IDisposable, System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class CommittableTransaction : System.Transactions.Transaction, IAsyncResult, IDisposable, System.Runtime.Serialization.ISerializable
type CommittableTransaction = class
    inherit Transaction
    interface ISerializable
    interface IDisposable
    interface IAsyncResult
Public NotInheritable Class CommittableTransaction
Inherits Transaction
Implements IAsyncResult, IDisposable, ISerializable
繼承
CommittableTransaction
屬性
實作

備註

CommittableTransaction 類別為應用程式提供使用交易的明確方式,而非隱含地使用 TransactionScope 類別。The CommittableTransaction class provides an explicit way for applications to use a transaction, as opposed to using the TransactionScope class implicitly. TransactionScope 類別不同的是,應用程式寫入器需要特別呼叫 CommitRollback 方法,才能認可或中止交易。Unlike the TransactionScope class, the application writer needs to specifically call the Commit and Rollback methods in order to commit or abort the transaction. 不過,只有交易的建立者可以認可交易。However, only the creator of a transaction can commit the transaction. 因此,透過Transaction.Clone方法取得之可認可交易的複本無法認可。Therefore, copies of a committable transaction obtained through the Transaction.Clone method are not committable.

注意

我們建議您使用TransactionScope類別建立隱含交易,以便為您自動管理環境交易內容。We recommend that you create implicit transactions using the TransactionScope class, so that the ambient transaction context is automatically managed for you. 針對需要在多個TransactionScope函數DependentTransaction調用或多個執行緒呼叫上使用相同交易的應用程式,您也應該使用和類別。You should also use the TransactionScope and DependentTransaction classes for applications that require the use of the same transaction across multiple function calls or multiple thread calls. 如需此模型的詳細資訊,請參閱使用交易範圍來執行隱含交易主題。For more information on this model, see the Implementing An Implicit Transaction Using Transaction Scope topic.

CommittableTransaction建立不會自動設定環境交易,這是您的程式碼執行的交易。Creating a CommittableTransaction does not automatically set the ambient transaction, which is the transaction your code executes in. 您可以藉由呼叫全域Transaction.Current Transaction物件的靜態屬性來取得或設定環境交易。You can get or set the ambient transaction by calling the static Transaction.Current property of the global Transaction object. 如需有關環境交易的詳細資訊,請參閱使用交易範圍來執行隱含交易主題中的「使用 TransactionScopeOption 管理交易流程」一節。For more information on ambient transactions, see the " Managing Transaction Flow using TransactionScopeOption" section of the Implementing An Implicit Transaction Using Transaction Scope topic. 如果未設定環境交易,資源管理員上的任何作業都不是該交易的一部分。If the ambient transaction is not set, any operation on a resource manager is not part of that transaction. 您必須明確設定並重設環境交易,以確保資源管理員在正確的交易內容下運作。You need to explicitly set and reset the ambient transaction to ensure that resource managers operate under the right transaction context.

CommittableTransaction在認可之前,與交易相關的所有資源仍會鎖定。Until a CommittableTransaction has been committed, all the resources involved with the transaction are still locked.

您無法重複使用 CommittableTransaction 物件,A CommittableTransaction object cannot be reused. 一旦認可或回復之後,就無法在交易中再次使用,或設定為目前的環境交易內容。Once it has been committed or rolled back, it cannot be used again in a transaction or set as the current ambient transaction context.

建構函式

CommittableTransaction()

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

CommittableTransaction(TimeSpan)

使用指定的 timeout 值,初始化 CommittableTransaction 類別的新執行個體。Initializes a new instance of the CommittableTransaction class with the specified timeout value.

CommittableTransaction(TransactionOptions)

使用指定的交易選項,初始化 CommittableTransaction 類別的新執行個體。Initializes a new instance of the CommittableTransaction class with the specified transaction options.

屬性

IsolationLevel

取得交易的隔離等級 (Isolation Level)。Gets the isolation level of the transaction.

(繼承來源 Transaction)
PromoterType

可唯一識別 byte[] 的格式,其由 Promote 方法在交易升級時傳回。Uniquely identifies the format of the byte[] returned by the Promote method when the transaction is promoted.

(繼承來源 Transaction)
TransactionInformation

擷取交易的其他資訊。Retrieves additional information about a transaction.

(繼承來源 Transaction)

方法

BeginCommit(AsyncCallback, Object)

開始嘗試非同步認可交易。Begins an attempt to commit the transaction asynchronously.

BeginCommitInternal(AsyncCallback) (繼承來源 Transaction)
Clone()

建立交易的複製品 (Clone)。Creates a clone of the transaction.

(繼承來源 Transaction)
Commit()

嘗試認可交易。Attempts to commit the transaction.

DependentClone(DependentCloneOption)

建立交易的相依複製品。Creates a dependent clone of the transaction.

(繼承來源 Transaction)
Dispose()

釋放該物件所持有的資源。Releases the resources that are held by the object.

(繼承來源 Transaction)
EndCommit(IAsyncResult)

結束非同步認可交易的嘗試。Ends an attempt to commit the transaction asynchronously.

EndCommitInternal(IAsyncResult) (繼承來源 Transaction)
EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions)

登記支援兩階段交易認可 (Two-Phase Commit) 的長期資源管理員以參與交易。Enlists a durable resource manager that supports two phase commit to participate in a transaction.

(繼承來源 Transaction)
EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions)

登記支援單一階段交易認可最佳化的長期資源管理員以參與交易。Enlists a durable resource manager that supports single phase commit optimization to participate in a transaction.

(繼承來源 Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification)

使用可提升單一階段登記 (PSPE) 來登記具有內部交易的資源管理員。Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE).

(繼承來源 Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid)

使用可提升單一階段登記 (PSPE) 來登記具有內部交易的資源管理員。Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE).

(繼承來源 Transaction)
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

登錄暫時性資源管理員,支援兩階段交易認可參與交易。Enlists a volatile resource manager that supports two phase commit to participate in a transaction.

(繼承來源 Transaction)
EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

登記支援單一階段交易認可最佳化的暫時性 (Volatile) 資源管理員以參與交易。Enlists a volatile resource manager that supports single phase commit optimization to participate in a transaction.

(繼承來源 Transaction)
Equals(Object)

判斷這個交易和指定的物件是否相等。Determines whether this transaction and the specified object are equal.

(繼承來源 Transaction)
GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

(繼承來源 Transaction)
GetPromotedToken()

當此交易升級時,取得 Promote 方法傳回的 byte[]Gets the byte[] returned by the Promote method when the transaction is promoted.

(繼承來源 Transaction)
GetType()

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

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions)

提升和登記支援兩階段交易認可 (Two-Phase Commit) 的長期資源管理員以參與異動。Promotes and enlists a durable resource manager that supports two phase commit to participate in a transaction.

(繼承來源 Transaction)
Rollback()

復原 (中止) 交易。Rolls back (aborts) the transaction.

(繼承來源 Transaction)
Rollback(Exception)

復原 (中止) 交易。Rolls back (aborts) the transaction.

(繼承來源 Transaction)
SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid)

設定非 MSDTC Promoter 所產生的分散式異動識別碼。Sets the distributed transaction identifier generated by the non-MSDTC promoter.

(繼承來源 Transaction)
ToString()

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

(繼承來源 Object)

事件

TransactionCompleted

指出交易已完成。Indicates that the transaction is completed.

(繼承來源 Transaction)

明確介面實作

IAsyncResult.AsyncState

取得當做 BeginCommit(AsyncCallback, Object) 方法呼叫之最後一個參數來提供的物件。Gets the object provided as the last parameter of the BeginCommit(AsyncCallback, Object) method call.

IAsyncResult.AsyncWaitHandle

取得 WaitHandle,用來等候非同步作業完成。Gets a WaitHandle that is used to wait for an asynchronous operation to complete.

IAsyncResult.CompletedSynchronously

取得非同步認可作業是否已同步完成的指示。Gets an indication of whether the asynchronous commit operation completed synchronously.

IAsyncResult.IsCompleted

取得非同步認可作業是否已完成的指示。Gets an indication whether the asynchronous commit operation has completed.

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

適用於

執行緒安全性

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

另請參閱