CommittableTransaction 类

定义

描述可提交的事务。Describes a committable transaction.

public ref class CommittableTransaction sealed : System::Transactions::Transaction, IAsyncResult
public ref class CommittableTransaction sealed : System::Transactions::Transaction, IAsyncResult, IDisposable, System::Runtime::Serialization::ISerializable
public sealed class CommittableTransaction : System.Transactions.Transaction, IAsyncResult
[System.Serializable]
public sealed class CommittableTransaction : System.Transactions.Transaction, IAsyncResult
[System.Serializable]
public sealed class CommittableTransaction : System.Transactions.Transaction, IAsyncResult, IDisposable, System.Runtime.Serialization.ISerializable
type CommittableTransaction = class
    inherit Transaction
    interface IAsyncResult
type CommittableTransaction = class
    inherit Transaction
    interface ISerializable
    interface IDisposable
    interface IAsyncResult
Public NotInheritable Class CommittableTransaction
Inherits Transaction
Implements 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. 还应将 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 对象的静态 Transaction.Current 属性来获取或设置环境事务。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

获取事务的隔离级别。Gets the isolation level of the transaction.

(继承自 Transaction)
PromoterType

对提升事务时由 Promote 方法返回的 byte [] 的格式进行唯一标识。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()

创建事务的克隆。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)

登记支持两阶段提交的持久资源管理器以参与事务。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)

登记支持单阶段提交优化的可变资源管理器以参与事务。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)

提升和登记支持两阶段提交的持久资源管理器以参与事务。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 提升程序生成的分布式事务标识符。Sets the distributed transaction identifier generated by the non-MSDTC promoter.

(继承自 Transaction)
ToString()

返回一个表示当前对象的 string。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

获取用于等待异步操作完成的 WaitHandleGets 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.

另请参阅