PreparingEnlistment.Prepared Methode

Definition

Gibt an, dass die Transaktion zugesichert werden kann.

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

Beispiele

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

Hinweise

In der ersten (Vorbereiten) Phase eines zweistufigen Commits ruft ein Ressourcenmanager, der die Prepare Methode der IEnlistmentNotification Schnittstelle implementiert, diese Methode auf, um anzugeben, dass die Transaktion zugesichert werden kann.

Der Ressourcenmanager kann die Done Methode jederzeit aufrufen, bevor sie diese Methode aufgerufen hat. Auf diese Weise wird die Auflistung eine schreibgeschützte Abstimmung abgegeben, d. h., sie stimmt über die Transaktion ab, muss aber nicht das endgültige Ergebnis erhalten.

Sobald diese Methode von einer Enlistment aufgerufen wird und bevor sie zurückgegeben wird, ist es möglich, dass ein anderer Thread oder dieserselbe Thread einen Aufruf an dieselbe Enlistment-Methode durchführen kann, Rollback z. B. zum Ausführen eines Rollbacks. Dies kann zu einer Deadlock-Situation führen, wenn die Ressourcen-Manager-Implementierung ressourcensperren erst nach der Rückgabe dieser Methode freigibt.

Gilt für: