語言

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 and Transaction 方法被調用來招募交易中的參與者時,它們會回傳描述該登錄的物件。

在交易提交的最後階段,交易管理器將此物件傳給實作 IEnlistmentNotification 已在交易中啟用的介面資源管理器。 具體來說,交易管理器會呼叫CommitRollback參與者的方法或方法,視後者是否決定提交或回滾交易而定。 參與者應呼叫 Done 該物件的方法,告知交易管理器已完成工作。

徵兵可以在方法尚未進入準備階段前的任何時間Done呼叫該Prepared方法。 透過此,登錄即投出唯讀投票,意即它對交易投承諾,但不必收到最終結果。 請注意,在呼叫該方法後 Done ,參與者不會再收到交易管理器的通知。

方法

名稱 Description
Done()

表示交易參與者已完成其工作。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於

執行緒安全性

此類型是安全線程。

另請參閱