Enlistment Classe

Definição

Facilita a comunicação entre um participante da transação alistado e o gestor da transação 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 seguinte 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

Observações

Quando os EnlistVolatile métodos e EnlistDurable do Transaction objeto são invocados para recrutar um participante numa transação, eles retornam este objeto descrevendo o alistamento.

Durante a fase final do commit da transação, o gestor de transações passa este objeto a um gestor de recursos que implementa a IEnlistmentNotification interface que foi registada numa transação. Especificamente, o gestor de transações chama ou CommitRollback o método do participante, dependendo se este último decidiu comprometer ou reverter a transação. O participante deve chamar o Done método deste objeto para informar o gestor de transações de que este concluiu o seu trabalho.

Um alistamento pode chamar o Done método a qualquer momento antes de ter iniciado Prepared a fase de preparação. 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. Note que, após o Done método ser chamado, o participante alistado não recebe mais notificações do gestor de transações.

Métodos

Name Description
Done()

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

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
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)
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