Enlistment Classe

Definição

Facilita a comunicação entre um participante de transação inscrito e o gerenciador de transações durante a fase final da transação.

public ref class Enlistment
public class Enlistment
type Enlistment = class
Public Class Enlistment
Herança
Enlistment
Derivado

Exemplos

O exemplo a seguir mostra uma implementação da IEnlistmentNotification interface e quando o Done método deve ser chamado.

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

Comentários

Quando o objeto e EnlistVolatile os EnlistDurableTransaction métodos são invocados para inscrever um participante em uma transação, eles retornam esse objeto descrevendo a inscrição.

Durante a fase final da confirmação da transação, o gerenciador de transações passa esse objeto para um gerenciador de recursos implementando a IEnlistmentNotification interface que se inscreveu em uma transação. Especificamente, o gerenciador de transações chama o Commit ou o Rollback método do participante, dependendo se este decidiu confirmar ou reverter a transação. O participante deve chamar o Done método desse objeto para informar ao gerenciador de transações que concluiu seu trabalho.

Uma inscrição pode chamar o método a Done qualquer momento antes de ser chamado Prepared na fase de preparação. Ao fazer isso, a inscrição está lançando um voto somente leitura, o que significa que ele vota confirmação na transação, mas não precisa receber o resultado final. Observe que, depois que o Done método é chamado, o participante inscrito não recebe mais notificações do gerenciador de transações.

Métodos

Nome Description
Done()

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

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a

Acesso thread-safe

Esse tipo é thread safe.

Confira também