Sdílet prostřednictvím


PreparingEnlistment Třída

Definice

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

public ref class PreparingEnlistment : System::Transactions::Enlistment
public class PreparingEnlistment : System.Transactions.Enlistment
type PreparingEnlistment = class
    inherit Enlistment
Public Class PreparingEnlistment
Inherits Enlistment
Dědičnost
PreparingEnlistment

Příklady

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

Během počáteční (příprava) fáze transakce správce transakcí předává tento typ správci prostředků voláním Prepare metody získat hlasování o prostředku transakce. V závislosti na tom, jestli hlasuje k potvrzení nebo vrácení zpět, by implementace správce prostředků měla volat Prepared nebo ForceRollback metody tohoto typu.

Správce prostředků může metodu Done volat také kdykoli předtím, než zavolá metodu Prepared . Tímto způsobem zařazení přetypuje hlasování jen pro čtení, což znamená, že hlasuje potvrzení o transakci, ale nemusí přijímat konečný výsledek.

Správci trvalých prostředků mohou načíst informace potřebné správcem transakcí pro opětovné zařazení z RecoveryInformation() vlastnosti. Další informace o obnovení najdete v tématu Provádění obnovení.

Metody

Name Description
Done()

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

(Zděděno od Enlistment)
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

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

Označuje, že transakce by se měla vrátit zpět.

ForceRollback(Exception)

Označuje, že transakce by se měla vrátit zpět.

GetHashCode()

Slouží jako výchozí funkce hash.

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

Získá Type aktuální instance.

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

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

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

Označuje, že transakce může být potvrzena.

RecoveryInformation()

Získá informace o obnovení zařazení.

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é