PreparingEnlistment.Prepared メソッド

定義

トランザクションをコミットできることを示します。

public:
 void Prepared();
public void Prepared ();
member this.Prepared : unit -> unit
Public Sub Prepared ()

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

注釈

2 フェーズ コミットの最初の (準備) フェーズでは、インターフェイスの メソッドIEnlistmentNotificationPrepare実装するリソース マネージャーがこのメソッドを呼び出して、トランザクションをコミットできることを示します。

リソース マネージャーは、このメソッドを Done 呼び出す前に、いつでも メソッドを呼び出すことができます。 これにより、参加リストは読み取り専用の投票を行います。つまり、トランザクションに対するコミットに投票しますが、最終的な結果を受け取る必要はありません。

このメソッドが参加リストによって呼び出され、それが返される前に、別のスレッドまたはこの同じスレッドが、ロールバックを実行するなど Rollback 、同じ参加メソッドを呼び出す可能性があります。 これにより、このメソッドが返されるまでリソース マネージャーの実装がリソース ロックを解放しない場合、デッドロックが発生する可能性があります。

適用対象