PreparingEnlistment 类

定义

促进登记的事务参与者与事务管理器之间在事务的准备阶段中的通信。

public ref class PreparingEnlistment : System::Transactions::Enlistment
public class PreparingEnlistment : System.Transactions.Enlistment
type PreparingEnlistment = class
    inherit Enlistment
Public Class PreparingEnlistment
Inherits Enlistment
继承
PreparingEnlistment

示例

class myEnlistmentClass : IEnlistmentNotification
{
    public void Prepare(PreparingEnlistment preparingEnlistment)
    {
        Console.WriteLine("Prepare notification received");

        //Perform transactional work

        //If work finished correctly, reply prepared
        preparingEnlistment.Prepared();

        // otherwise, do a ForceRollback
        preparingEnlistment.ForceRollback();
    }

    public void Commit(Enlistment enlistment)
    {
        Console.WriteLine("Commit notification received");

        //Do any work necessary when commit notification is received

        //Declare done on the enlistment
        enlistment.Done();
    }

    public void Rollback(Enlistment enlistment)
    {
        Console.WriteLine("Rollback notification received");

        //Do any work necessary when rollback notification is received

        //Declare done on the enlistment
        enlistment.Done();
    }

    public void InDoubt(Enlistment enlistment)
    {
        Console.WriteLine("In doubt notification received");

        //Do any work necessary when indout notification is received
        
        //Declare done on the enlistment
        enlistment.Done();
    }
}
Public Class EnlistmentClass
    Implements IEnlistmentNotification

    Public Sub Prepare(ByVal myPreparingEnlistment As PreparingEnlistment) Implements System.Transactions.IEnlistmentNotification.Prepare
        Console.WriteLine("Prepare notification received")

        'Perform transactional work

        'If work finished correctly, reply with prepared
        myPreparingEnlistment.Prepared()
    End Sub

    Public Sub Commit(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Commit
        Console.WriteLine("Commit notification received")

        'Do any work necessary when commit notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub

    Public Sub Rollback(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Rollback
        Console.WriteLine("Rollback notification received")

        'Do any work necessary when rollback notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub

    Public Sub InDoubt(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.InDoubt
        Console.WriteLine("In doubt notification received")

        'Do any work necessary when indout notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub
End Class

注解

在事务的初始 (准备) 阶段期间,事务管理器通过调用 Prepare 方法来获取资源对事务的投票,将此类型传递给资源管理器。 根据是投票提交还是回滚,资源管理器的实现应调用 Prepared 此类型的 或 ForceRollback 方法。

资源管理器还可以在调用 Done 方法之前随时调用 Prepared 方法。 通过这样做,登记将进行只读投票,这意味着它对事务的提交进行投票,但不需要接收最终结果。

持久资源管理器可以从 属性检索事务管理器重新登记 RecoveryInformation 所需的信息。 有关恢复的更多信息,请参见执行恢复

方法

Done()

指示事务参与者已完成其工作。

(继承自 Enlistment)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
ForceRollback()

指示应回滚事务。

ForceRollback(Exception)

指示应回滚事务。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Prepared()

指示可以提交事务。

RecoveryInformation()

获取登记的恢复信息。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

线程安全性

此类型是线程安全的。

另请参阅