Transaction.EnlistVolatile Methode

Definitie

Neemt een vluchtige resourcemanager in om deel te nemen aan een transactie.

Overloads

Name Description
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Hiermee wordt een vluchtige resourcemanager opgenomen die ondersteuning biedt voor twee fasen om deel te nemen aan een transactie.

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Neemt een vluchtige resourcemanager op die ondersteuning biedt voor optimalisatie van één fase voor doorvoeren om deel te nemen aan een transactie.

Opmerkingen

Vluchtige resourcebeheerders kunnen niet herstellen van het niet voltooien van een transactie waarin ze deelnamen. Zie Implementing A Resource Manager voor meer informatie over vluchtige en duurzame resources en hoe u een resource kunt inschakelen. Zie Een transactie doorvoeren in Single-Phase en meerdere fasen voor meer informatie over hoe een resourcemanager reageert op doorvoermeldingen en de doorvoer voorbereiden.

EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Bron:
Transaction.cs
Bron:
Transaction.cs
Bron:
Transaction.cs
Bron:
Transaction.cs
Bron:
Transaction.cs

Hiermee wordt een vluchtige resourcemanager opgenomen die ondersteuning biedt voor twee fasen om deel te nemen aan een transactie.

public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::IEnlistmentNotification ^ enlistmentNotification, System::Transactions::EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile(System.Transactions.IEnlistmentNotification enlistmentNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
member this.EnlistVolatile : System.Transactions.IEnlistmentNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (enlistmentNotification As IEnlistmentNotification, enlistmentOptions As EnlistmentOptions) As Enlistment

Parameters

enlistmentNotification
IEnlistmentNotification

Een object waarmee de IEnlistmentNotification interface wordt geïmplementeerd voor het ontvangen van doorvoermeldingen in twee fasen.

enlistmentOptions
EnlistmentOptions

EnlistDuringPrepareRequired als de Resource Manager extra werk wil uitvoeren tijdens de voorbereidingsfase.

Retouren

Een Enlistment object dat de opname beschrijft.

Voorbeelden

In het volgende voorbeeld ziet u een implementatie van de interface, evenals het inschakelen van het object als deelnemer aan een transactie met behulp van IEnlistmentNotification de EnlistVolatile methode.

static void Main(string[] args)
{
    try
    {
        using (TransactionScope scope = new TransactionScope())
        {
        
            //Create an enlistment object
            myEnlistmentClass myElistment = new myEnlistmentClass();

            //Enlist on the current transaction with the enlistment object
            Transaction.Current.EnlistVolatile(myElistment, EnlistmentOptions.None);

            //Perform transactional work here.

            //Call complete on the TransactionScope based on console input
                            ConsoleKeyInfo c;
            while(true)
                            {
                Console.Write("Complete the transaction scope? [Y|N] ");
                c = Console.ReadKey();
                Console.WriteLine();
        
                                    if ((c.KeyChar == 'Y') || (c.KeyChar == 'y'))
                {
                    scope.Complete();
                    break;
                }
                else if ((c.KeyChar == 'N') || (c.KeyChar == 'n'))
                {
                    break;
                }
            }
        }
    }
    catch (System.Transactions.TransactionException ex)
    {
        Console.WriteLine(ex);
    }
    catch
    {
        Console.WriteLine("Cannot complete transaction");
        throw;
    }
}

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 Shared Sub Main()
        Try
            Using scope As TransactionScope = New TransactionScope()

                'Create an enlistment object
                Dim myEnlistmentClass As New EnlistmentClass

                'Enlist on the current transaction with the enlistment object
                Transaction.Current.EnlistVolatile(myEnlistmentClass, EnlistmentOptions.None)

                'Perform transactional work here.

                'Call complete on the TransactionScope based on console input
                Dim c As ConsoleKeyInfo
                While (True)
                    Console.Write("Complete the transaction scope? [Y|N] ")
                    c = Console.ReadKey()
                    Console.WriteLine()
                    If (c.KeyChar = "Y") Or (c.KeyChar = "y") Then
                        scope.Complete()
                        Exit While
                    ElseIf ((c.KeyChar = "N") Or (c.KeyChar = "n")) Then
                        Exit While
                    End If
                End While
            End Using
        Catch ex As TransactionException
            Console.WriteLine(ex)
        Catch
            Console.WriteLine("Cannot complete transaction")
            Throw
        End Try
    End Sub
End Class

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

Opmerkingen

Vluchtige resourcebeheerders kunnen niet herstellen van het niet voltooien van een transactie waarin ze deelnamen. Gebruik de EnlistDurable methode om een duurzame opname in een transactie te verkrijgen.

Resourcemanagers die zijn ingeschreven voor deelname aan een transactie via deze methode, ontvangen twee fasedoorvoermeldingen die overeenkomen met de methoden die op de IEnlistmentNotification interface zijn gedefinieerd.

Van toepassing op

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Bron:
Transaction.cs
Bron:
Transaction.cs
Bron:
Transaction.cs
Bron:
Transaction.cs
Bron:
Transaction.cs

Neemt een vluchtige resourcemanager op die ondersteuning biedt voor optimalisatie van één fase voor doorvoeren om deel te nemen aan een transactie.

public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::ISinglePhaseNotification ^ singlePhaseNotification, System::Transactions::EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile(System.Transactions.ISinglePhaseNotification singlePhaseNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
member this.EnlistVolatile : System.Transactions.ISinglePhaseNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (singlePhaseNotification As ISinglePhaseNotification, enlistmentOptions As EnlistmentOptions) As Enlistment

Parameters

singlePhaseNotification
ISinglePhaseNotification

Een object dat de ISinglePhaseNotification interface implementeert die de doorvoer van één fase en twee fasedoorvoermeldingen moet kunnen ontvangen.

enlistmentOptions
EnlistmentOptions

EnlistDuringPrepareRequired als de Resource Manager extra werk wil uitvoeren tijdens de voorbereidingsfase.

Retouren

Een Enlistment object dat de opname beschrijft.

Opmerkingen

Vluchtige resourcebeheerders kunnen niet herstellen van het niet voltooien van een transactie waarin ze deelnamen. Gebruik de EnlistDurable methode om een duurzame opname in een transactie te verkrijgen. Zie Implementing A Resource Manager voor meer informatie over vluchtige en duurzame resources en hoe u een resource kunt inschakelen. Zie Een transactie doorvoeren in Single-Phase en meerdere fasen voor meer informatie over hoe een resourcemanager reageert op doorvoermeldingen en de doorvoer voorbereiden.

U moet er rekening mee houden dat zelfs wanneer uw Resource Manager-implementatie bij deze methode wordt ingeschreven, het niet gegarandeerd is dat er één fasedoorvoering wordt uitgevoerd. De transactiebeheerder kan in plaats daarvan nog steeds twee fasedoorvoermeldingen verzenden. Zie Optimalisatie met single phase Commit en Promotable Single Phase Notification voor meer informatie over de optimalisatie van doorvoeren met één fase.

Van toepassing op