Partager via


Transaction.EnlistVolatile Méthode

Définition

Inscrit un gestionnaire de ressources volatile pour participer à une transaction.

Surcharges

Nom Description
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Inscrit un gestionnaire de ressources volatile qui prend en charge la validation en deux phases pour participer à une transaction.

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Inscrit un gestionnaire de ressources volatile qui prend en charge l’optimisation de validation par phase unique pour participer à une transaction.

Remarques

Les gestionnaires de ressources volatiles ne peuvent pas se récupérer de l’échec de l’exécution d’une transaction dans laquelle ils participaient.

EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Source:
Transaction.cs
Source:
Transaction.cs
Source:
Transaction.cs
Source:
Transaction.cs
Source:
Transaction.cs

Inscrit un gestionnaire de ressources volatile qui prend en charge la validation en deux phases pour participer à une 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

Paramètres

enlistmentNotification
IEnlistmentNotification

Objet qui implémente l’interface IEnlistmentNotification pour recevoir des notifications de validation en deux phases.

enlistmentOptions
EnlistmentOptions

EnlistDuringPrepareRequired si le gestionnaire de ressources souhaite effectuer des tâches supplémentaires pendant la phase de préparation.

Retours

Objet Enlistment qui décrit l’inscription.

Exemples

L’exemple suivant montre une implémentation de l’interface, ainsi que l’inscription de IEnlistmentNotification l’objet en tant que participant à une transaction à l’aide de la EnlistVolatile méthode.

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

Remarques

Les gestionnaires de ressources volatiles ne peuvent pas se récupérer de l’échec de l’exécution d’une transaction dans laquelle ils participaient. Pour obtenir une inscription durable dans une transaction, utilisez la EnlistDurable méthode.

Les gestionnaires de ressources inscrits pour participer à une transaction par le biais de cette méthode reçoivent des notifications de validation en deux phases qui correspondent aux méthodes définies sur l’interface IEnlistmentNotification .

S’applique à

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Source:
Transaction.cs
Source:
Transaction.cs
Source:
Transaction.cs
Source:
Transaction.cs
Source:
Transaction.cs

Inscrit un gestionnaire de ressources volatile qui prend en charge l’optimisation de validation par phase unique pour participer à une 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

Paramètres

singlePhaseNotification
ISinglePhaseNotification

Objet qui implémente l’interface ISinglePhaseNotification qui doit être en mesure de recevoir une validation de phase unique et deux notifications de validation de phase.

enlistmentOptions
EnlistmentOptions

EnlistDuringPrepareRequired si le gestionnaire de ressources souhaite effectuer des tâches supplémentaires pendant la phase de préparation.

Retours

Objet Enlistment qui décrit l’inscription.

Remarques

Les gestionnaires de ressources volatiles ne peuvent pas se récupérer de l’échec de l’exécution d’une transaction dans laquelle ils participaient. Pour obtenir une inscription durable dans une transaction, utilisez la EnlistDurable méthode.

Notez que même lorsque votre implémentation resource manager s’inscrit avec cette méthode, elle n’est pas garantie qu’elle reçoit une validation de phase unique. Le gestionnaire de transactions peut toujours envoyer des notifications de validation en deux phases à la place.

S’applique à