PreparingEnlistment Klass

Definition

Underlättar kommunikationen mellan en registrerad transaktionsdeltagare och transaktionshanteraren under förberedelsefasen av transaktionen.

public ref class PreparingEnlistment : System::Transactions::Enlistment
public class PreparingEnlistment : System.Transactions.Enlistment
type PreparingEnlistment = class
    inherit Enlistment
Public Class PreparingEnlistment
Inherits Enlistment
Arv
PreparingEnlistment

Exempel

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

Kommentarer

Under den inledande (förbereda) fasen av transaktionen skickar transaktionshanteraren den här typen till resurshanteraren genom att anropa Prepare metoden för att få en resurs att rösta på transaktionen. Beroende på om den röstar för att checka in eller återställa, bör din implementering av resurshanteraren anropa Prepared metoderna eller ForceRollback av den här typen.

Resurshanteraren kan också anropa Done metoden när som helst innan den har anropat Prepared metoden. Genom att göra det lägger värnplikten en skrivskyddad röst, vilket innebär att den röstar för transaktionen men inte behöver få det slutliga resultatet.

Hållbara resurshanterare kan hämta den information som krävs av transaktionshanteraren för återregistrering från RecoveryInformation() egenskapen. Mer information om återställning finns i Utföra återställning.

Metoder

Name Description
Done()

Anger att transaktionsdeltagaren har slutfört sitt arbete.

(Ärvd från Enlistment)
Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
ForceRollback()

Anger att transaktionen ska återställas.

ForceRollback(Exception)

Anger att transaktionen ska återställas.

GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
Prepared()

Anger att transaktionen kan genomföras.

RecoveryInformation()

Hämtar återställningsinformationen för en lista.

ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Gäller för

Trådsäkerhet

Den här typen är trådsäker.

Se även