CommittableTransaction CommittableTransaction CommittableTransaction CommittableTransaction Class

定義

描述可認可的交易。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
繼承
CommittableTransactionCommittableTransactionCommittableTransactionCommittableTransaction
屬性
實作

備註

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. 您也應該使用TransactionScopeDependentTransaction需要使用相同的異動,跨多個函式呼叫或多個執行緒呼叫的應用程式的類別。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() CommittableTransaction() CommittableTransaction()

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

CommittableTransaction(TimeSpan) CommittableTransaction(TimeSpan) CommittableTransaction(TimeSpan) CommittableTransaction(TimeSpan)

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

CommittableTransaction(TransactionOptions) CommittableTransaction(TransactionOptions) CommittableTransaction(TransactionOptions) CommittableTransaction(TransactionOptions)

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

方法

BeginCommit(AsyncCallback, Object) BeginCommit(AsyncCallback, Object) BeginCommit(AsyncCallback, Object) BeginCommit(AsyncCallback, Object)

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

BeginCommitInternal(AsyncCallback) BeginCommitInternal(AsyncCallback) BeginCommitInternal(AsyncCallback) BeginCommitInternal(AsyncCallback) Inherited from Transaction
Clone() Clone() Clone() Clone()

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

(Inherited from Transaction)
Commit() Commit() Commit() Commit()

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

DependentClone(DependentCloneOption) DependentClone(DependentCloneOption) DependentClone(DependentCloneOption) DependentClone(DependentCloneOption)

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

(Inherited from Transaction)
Dispose() Dispose() Dispose() Dispose()

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

(Inherited from Transaction)
EndCommit(IAsyncResult) EndCommit(IAsyncResult) EndCommit(IAsyncResult) EndCommit(IAsyncResult)

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

EndCommitInternal(IAsyncResult) EndCommitInternal(IAsyncResult) EndCommitInternal(IAsyncResult) EndCommitInternal(IAsyncResult) Inherited from Transaction
EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions)

登記支援兩階段交易認可參與交易的永久性資源管理員。Enlists a durable resource manager that supports two phase commit to participate in a transaction.

(Inherited from Transaction)
EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions)

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

(Inherited from Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification)

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

(Inherited from Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid)

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

(Inherited from Transaction)
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

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

(Inherited from Transaction)
EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

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

(Inherited from Transaction)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Transaction)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Transaction)
GetPromotedToken() GetPromotedToken() GetPromotedToken() GetPromotedToken()

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

(Inherited from Transaction)
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)
PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions)

登記支援兩階段交易認可參與交易的永久性資源管理員和升級。Promotes and enlists a durable resource manager that supports two phase commit to participate in a transaction.

(Inherited from Transaction)
Rollback() Rollback() Rollback() Rollback()

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

(Inherited from Transaction)
Rollback(Exception) Rollback(Exception) Rollback(Exception) Rollback(Exception)

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

(Inherited from Transaction)
SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid)

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

(Inherited from Transaction)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

明確介面實作

IAsyncResult.AsyncState IAsyncResult.AsyncState IAsyncResult.AsyncState IAsyncResult.AsyncState

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

IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle

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

IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously

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

IAsyncResult.IsCompleted IAsyncResult.IsCompleted IAsyncResult.IsCompleted IAsyncResult.IsCompleted

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

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

屬性

IsolationLevel IsolationLevel IsolationLevel IsolationLevel

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

(Inherited from Transaction)
PromoterType PromoterType PromoterType PromoterType

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

(Inherited from Transaction)
TransactionInformation TransactionInformation TransactionInformation TransactionInformation

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

(Inherited from Transaction)

事件

TransactionCompleted TransactionCompleted TransactionCompleted TransactionCompleted

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

(Inherited from Transaction)

適用於

執行緒安全性

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

另請參閱