Share via


PreparingEnlistment.Prepared Méthode

Définition

Indique que la transaction peut être validée.

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

Exemples

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

Remarques

Dans la première phase (préparer) d’une validation à deux phases, un gestionnaire de ressources implémentant la Prepare méthode de l’interface IEnlistmentNotification , appelle cette méthode pour indiquer que la transaction peut être validée.

Le gestionnaire de ressources peut appeler la Done méthode à tout moment avant d’avoir appelé cette méthode. Dans ce cas, l’inscription porte un vote en lecture seule, ce qui signifie qu’elle vote sur la transaction, mais n’a pas besoin de recevoir le résultat final.

Une fois cette méthode appelée par une inscription et avant son retour, il est possible qu’un autre thread ou ce même thread puisse effectuer un appel dans la même méthode d’inscription, comme Rollback pour effectuer une restauration. Cela peut entraîner un blocage si l’implémentation de Resource Manager ne libère pas les verrous de ressources tant qu’une fois cette méthode retournée.

S’applique à