PreparingEnlistment Classe

Definição

Facilita a comunicação entre um participante da transação alistado e o gestor da transação durante a fase de Preparação da transação.

public ref class PreparingEnlistment : System::Transactions::Enlistment
public class PreparingEnlistment : System.Transactions.Enlistment
type PreparingEnlistment = class
    inherit Enlistment
Public Class PreparingEnlistment
Inherits Enlistment
Herança
PreparingEnlistment

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

Durante a fase inicial (preparação) da transação, o gestor de transações passa este tipo ao gestor de recursos ao chamar o Prepare método para obter o voto de um recurso sobre a transação. Dependendo se vota para comprometer ou reverter, a tua implementação do gestor de recursos deve chamar os Prepared métodos ou ForceRollback deste tipo.

O gestor de recursos também pode chamar o Done método a qualquer momento antes de ele ter chamado o Prepared 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.

Gestores de recursos duradouros podem recuperar a informação necessária ao gestor de transações para a readmissão da RecoveryInformation() propriedade. Para obter mais informações sobre recuperação, consulte Executando recuperação.

Métodos

Name Description
Done()

Indica que o participante da transação concluiu o seu trabalho.

(Herdado de Enlistment)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
ForceRollback()

Indica que a transação deve ser revertida.

ForceRollback(Exception)

Indica que a transação deve ser revertida.

GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
Prepared()

Indica que a transação pode ser confirmada.

RecoveryInformation()

Obtém a informação de recuperação de um alistamento.

ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Aplica-se a

Segurança de Thread

Este tipo é seguro para fios.

Ver também