PreparingEnlistment.Prepared Metoda

Definicja

Wskazuje, że transakcja może zostać zatwierdzona.

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

Przykłady

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

Uwagi

W pierwszej fazie (przygotowanie) zatwierdzenia dwufazowego menedżer zasobów implementujący Prepare metodę interfejsu IEnlistmentNotification wywołuje tę metodę, aby wskazać, że transakcja może zostać zatwierdzona.

Menedżer zasobów może wywołać metodę Done w dowolnym momencie, zanim wywoła tę metodę. W ten sposób rejestracja rzutuje głos tylko do odczytu, co oznacza, że głosuje za zatwierdzeniem transakcji, ale nie musi otrzymywać końcowego wyniku.

Po wywołaniu tej metody przez rejestrację i przed jej zwróceniem możliwe jest, że inny wątek lub ten sam wątek może wywołać tę samą metodę rejestracji, taką jak Rollback wykonywanie wycofywania. Może to spowodować zakleszczenie, jeśli implementacja menedżera zasobów nie zwalnia blokad zasobów do momentu powrotu tej metody.

Dotyczy