Enlistment Třída

Definice

Usnadňuje komunikaci mezi účastníkem zařazené transakce a správcem transakcí během poslední fáze transakce.

public ref class Enlistment
public class Enlistment
type Enlistment = class
Public Class Enlistment
Dědičnost
Enlistment
Odvozené

Příklady

Následující příklad ukazuje implementaci IEnlistmentNotification rozhraní a kdy Done by měla být volána metoda.

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

Poznámky

EnlistVolatileEnlistDurable Když a metody objektu Transaction jsou vyvolány pro zařazení účastníka do transakce, vrátí tento objekt popisující zařazení.

Během poslední fáze potvrzení transakce správce transakcí předá tento objekt správci prostředků implementuje IEnlistmentNotification rozhraní, které bylo zapsáno v transakci. Konkrétně správce transakcí volá metodu Commit nebo Rollback účastníka v závislosti na tom, zda se rozhodl potvrdit nebo vrátit zpět transakci. Účastník by měl volat metodu Done tohoto objektu, aby správce transakcí věděl, že dokončil svou práci.

Zařazení může volat metodu Done kdykoli před voláním Prepared ve fázi přípravy. Tímto způsobem zařazení přetypuje hlas jen pro čtení, což znamená, že hlasuje potvrzení transakce, ale nemusí obdržet konečný výsledek. Všimněte si, že po zavolání Done metody účastník zařazení neobdrží žádná další oznámení od správce transakcí.

Metody

Done()

Označuje, že účastník transakce dokončil svou práci.

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Bezpečný přístup z více vláken

Tento typ je bezpečný pro přístup z více vláken.

Viz také