Enlistment Klasa

Definicja

Ułatwia komunikację między uczestnikiem transakcji na liście a menedżerem transakcji w ostatniej fazie transakcji.

public ref class Enlistment
public class Enlistment
type Enlistment = class
Public Class Enlistment
Dziedziczenie
Enlistment
Pochodne

Przykłady

W poniższym przykładzie przedstawiono implementację interfejsu IEnlistmentNotification i wywołanie Done metody .

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

Uwagi

EnlistVolatile Gdy metody Transaction i EnlistDurable obiektu są wywoływane w celu zarejestrowania uczestnika w transakcji, zwracają ten obiekt opisujący rejestrację.

W ostatniej fazie zatwierdzania transakcji menedżer transakcji przekazuje ten obiekt do menedżera zasobów implementujące IEnlistmentNotification interfejs, który został wymieniony w transakcji. W szczególności menedżer transakcji wywołuje metodę Commit lub Rollback metodę uczestnika, w zależności od tego, czy ta ostatnia zdecydowała się zatwierdzić lub wycofać transakcję. Uczestnik powinien wywołać metodę tego obiektu, Done aby poinformować menedżera transakcji, że zakończył swoją pracę.

Rejestracja może wywołać metodę Done w dowolnym momencie, zanim wywołana Prepared w fazie przygotowywania. W ten sposób rejestracja rzutuje głos tylko do odczytu, co oznacza, że głosuje za zatwierdzeniem transakcji, ale nie musi otrzymywać końcowego wyniku. Należy pamiętać, że po wywołaniu Done metody uczestnik na liście nie otrzymuje żadnych dalszych powiadomień od menedżera transakcji.

Metody

Done()

Wskazuje, że uczestnik transakcji wykonał swoją pracę.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Bezpieczeństwo wątkowe

Ten typ jest bezpieczny wątkowo.

Zobacz też