Enlistment 类

定义

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

public ref class Enlistment
public class Enlistment
type Enlistment = class
Public Class Enlistment
继承
Enlistment
派生

示例

以下示例演示 接口的 IEnlistmentNotification 实现,以及 Done 何时应调用 方法。

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

注解

EnlistVolatile当调用 对象的 和 EnlistDurable 方法Transaction以在事务中登记参与者时,它们返回描述登记的此对象。

在事务提交的最后阶段,事务管理器将此对象传递给实现已在事务中登记的 IEnlistmentNotification 接口的资源管理器。 具体而言,事务管理器调用 Commit 参与者的 或 Rollback 方法,具体取决于后者是否决定提交或回滚事务。 参与者应调用 Done 此 对象的 方法,让事务管理器知道它已完成其工作。

登记可以在准备阶段调用之前随时调用 DonePrepared 方法。 通过这样做,登记将进行只读投票,这意味着它会对事务进行提交投票,但不需要接收最终结果。 请注意,调用 方法后 Done ,登记的参与者不会收到来自事务管理器的进一步通知。

方法

Done()

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

Equals(Object)

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

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

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

(继承自 Object)

适用于

线程安全性

此类型是线程安全的。

另请参阅