PreparingEnlistment.Prepared Metod

Definition

Anger att transaktionen kan genomföras.

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

Exempel

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

Kommentarer

I den första (förbereda) fasen i en tvåfasincheckning anropar en resurshanterare som implementerar Prepare -metoden för IEnlistmentNotification gränssnittet den här metoden för att indikera att transaktionen kan genomföras.

Resurshanteraren kan anropa Done metoden när som helst innan den har anropat den här metoden. Genom att göra det lägger värnplikten en skrivskyddad röst, vilket innebär att den röstar för transaktionen men inte behöver få det slutliga resultatet.

När den här metoden anropas av en lista och innan den returneras är det möjligt att en annan tråd eller samma tråd kan göra ett anrop till samma anropsmetod, till exempel Rollback för att utföra en återställning. Detta kan leda till ett dödläge om resource manager-implementeringen inte frigör resurslås förrän den här metoden har returnerats.

Gäller för