PreparingEnlistment.Prepared Método

Definição

Indica que a transação pode ser confirmada.

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

Exemplos

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

Observações

Na primeira fase (preparar) de um commit em duas fases, um gestor de recursos que implementa o Prepare método da IEnlistmentNotification interface chama este método para indicar que a transação pode ser confirmada.

O gestor de recursos pode chamar o Done método a qualquer momento antes de este ter chamado este método. Ao fazê-lo, o alistamento está a emitir um voto apenas de leitura, o que significa que vota o commit na transação, mas não precisa de receber o resultado final.

Uma vez que este método é chamado por um enlistment e antes de regressar, é possível que outro thread ou este mesmo thread possa fazer uma chamada para o mesmo método de alistamento, como Rollback para realizar um rollback. Isto pode resultar numa situação de deadlock se a implementação do gestor de recursos não libertar bloqueios de recursos até depois deste método regressar.

Aplica-se a