Transaction.EnlistVolatile Metod

Definition

Registrerar en beständig resurshanterare för att delta i en transaktion.

Överlagringar

Name Description
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Enlists a volatile resource manager that supports two phase commit to participate in a transaction.

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Enlists a volatile resource manager that supports single phase commit optimization to participate in a transaction.

Kommentarer

Flyktiga resurshanterare kan inte återställas från att det inte gick att slutföra en transaktion där de deltog. Mer information om flyktiga och varaktiga resurser samt hur du registrerar en resurs finns i Implementing A Resource Manager. Mer information om hur en resurshanterare svarar på incheckningsmeddelanden och förbereder incheckningen finns i Commiting A Transaction In Single-Phase and Multi-Phase (Genomför en transaktion i Single-Phase och flera faser).

EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Källa:
Transaction.cs
Källa:
Transaction.cs
Källa:
Transaction.cs
Källa:
Transaction.cs
Källa:
Transaction.cs

Enlists a volatile resource manager that supports two phase commit to participate in a transaction.

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

Parametrar

enlistmentNotification
IEnlistmentNotification

Ett objekt som implementerar IEnlistmentNotification gränssnittet för att ta emot incheckningsmeddelanden i två faser.

enlistmentOptions
EnlistmentOptions

EnlistDuringPrepareRequired om resurshanteraren vill utföra ytterligare arbete under förberedelsefasen.

Returer

Ett Enlistment objekt som beskriver registreringen.

Exempel

I följande exempel visas en implementering av gränssnittet samt en lista över objektet som deltagare i en transaktion med hjälp av IEnlistmentNotificationEnlistVolatile metoden.

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

Kommentarer

Flyktiga resurshanterare kan inte återställas från att det inte gick att slutföra en transaktion där de deltog. Använd metoden för att få en varaktig registrering i en transaktion EnlistDurable .

Resursansvariga som är registrerade för deltagande i en transaktion via den här metoden får två aviseringar om fasincheckning som motsvarar de metoder som definierats i IEnlistmentNotification gränssnittet.

Gäller för

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Källa:
Transaction.cs
Källa:
Transaction.cs
Källa:
Transaction.cs
Källa:
Transaction.cs
Källa:
Transaction.cs

Enlists a volatile resource manager that supports single phase commit optimization to participate in a transaction.

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

Parametrar

singlePhaseNotification
ISinglePhaseNotification

Ett objekt som implementerar gränssnittet ISinglePhaseNotification som måste kunna ta emot enfasincheckning och två aviseringar om fasincheckning.

enlistmentOptions
EnlistmentOptions

EnlistDuringPrepareRequired om resurshanteraren vill utföra ytterligare arbete under förberedelsefasen.

Returer

Ett Enlistment objekt som beskriver registreringen.

Kommentarer

Flyktiga resurshanterare kan inte återställas från att det inte gick att slutföra en transaktion där de deltog. Använd metoden för att få en varaktig registrering i en transaktion EnlistDurable . Mer information om flyktiga och varaktiga resurser samt hur du registrerar en resurs finns i Implementing A Resource Manager. Mer information om hur en resurshanterare svarar på incheckningsmeddelanden och förbereder incheckningen finns i Commiting A Transaction In Single-Phase and Multi-Phase (Genomför en transaktion i Single-Phase och flera faser).

Observera att även när din resource manager-implementering registreras med den här metoden är det inte garanterat att den tar emot en enda fasincheckning. Transaktionshanteraren kan fortfarande skicka två fasincheckningsmeddelanden i stället. Mer information om optimering av enfasincheckning finns i Optimering med enfasincheckning och meddelande om enkel fas.

Gäller för