PreparingEnlistment.Prepared メソッド

定義

トランザクションをコミットできることを示します。Indicates that the transaction can be committed.

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フェーズコミットの最初の (準備) フェーズでは、 Prepare IEnlistmentNotificationインターフェイスのメソッドを実装するリソースマネージャーがこのメソッドを呼び出して、トランザクションをコミットできることを示します。In the first (prepare) phase of a two phase commit, a resource manager implementing the Prepare method of the IEnlistmentNotification interface, calls this method to indicate that the transaction can be committed.

リソースマネージャーは、このメソッドDoneを呼び出す前に、いつでもメソッドを呼び出すことができます。The resource manager can call the Done method at anytime before it has called this method. これにより、参加リストは読み取り専用の投票にキャストします。つまり、トランザクションに対してコミットを投票しますが、最終的な結果を受け取る必要はありません。By doing so, the enlistment is casting a read only vote, meaning that it votes commit on the transaction but does not need to receive the final outcome.

このメソッドが参加リストによって呼び出され、制御が戻る前に、別のスレッドまたは同じスレッドが、などの同じ参加メソッドを呼び出してRollbackロールバックを実行できる可能性があります。Once this method is called by an enlistment and before it returns, it is possible that another thread or this same thread could make a call into the same enlistment method such as Rollback to perform a rollback. このメソッドが返されるまで、リソースマネージャーの実装でリソースロックが解放されない場合は、デッドロック状態が発生する可能性があります。This can result in a deadlock situation if the resource manager implementation does not release resource locks until after this method returns.

適用対象