Transaction.EnlistVolatile Method

Definition

Inscreve um Resource Manager volátil para participar de uma transação.Enlists a volatile resource manager to participate in a transaction.

Overloads

EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Inscreve um Resource Manager volátil que dá suporte à confirmação em duas fases para participar de uma transação.Enlists a volatile resource manager that supports two phase commit to participate in a transaction.

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Inscreve um Resource Manager volátil que dá suporte à otimização em fase única para participar de uma transação.Enlists a volatile resource manager that supports single phase commit optimization to participate in a transaction.

Remarks

Os gerenciadores de recursos voláteis não podem recuperar de falhas para concluir uma transação na qual estavam participando.Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. Para obter mais informações sobre os recursos voláteis e duráveis, bem como para inscrever um recurso, consulte implementando um Gerenciador de recursos.For more information on volatile and durable resources, as well as how to enlist a resource, see Implementing A Resource Manager. Para obter mais informações sobre como um Gerenciador de recursos responde à notificação de confirmação e à preparação da confirmação, consulte confirmando uma transação em fase única e várias fases.For more information on how a resource manager responds to commit notification and prepare the commit, see Committing A Transaction In Single-Phase and Multi-Phase.

EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Inscreve um Resource Manager volátil que dá suporte à confirmação em duas fases para participar de uma transação.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 ^ notification, System::Transactions::EnlistmentOptions options);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.IEnlistmentNotification enlistmentNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.IEnlistmentNotification notification, System.Transactions.EnlistmentOptions options);
member this.EnlistVolatile : System.Transactions.IEnlistmentNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
member this.EnlistVolatile : System.Transactions.IEnlistmentNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (enlistmentNotification As IEnlistmentNotification, enlistmentOptions As EnlistmentOptions) As Enlistment
Public Function EnlistVolatile (notification As IEnlistmentNotification, options As EnlistmentOptions) As Enlistment

Parameters

enlistmentNotificationnotification
IEnlistmentNotification

Um objeto que implementa a interface IEnlistmentNotification para receber notificações de confirmação em duas fases.An object that implements the IEnlistmentNotification interface to receive two-phase commit notifications.

enlistmentOptionsoptions
EnlistmentOptions

EnlistDuringPrepareRequired se o gerenciador de recursos desejar realizar trabalho adicional durante a fase de preparação.EnlistDuringPrepareRequired if the resource manager wants to perform additional work during the prepare phase.

Returns

Enlistment

Um objeto Enlistment que descreve a inscrição.An Enlistment object that describes the enlistment.

Examples

O exemplo a seguir mostra uma implementação de IEnlistmentNotification interface, bem como a lista de objetos como um participante em uma transação usando o método EnlistVolatile.The following example shows an implementation of IEnlistmentNotification interface, as well as enlisting the object as a participant in a transaction using the EnlistVolatile method.

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

Remarks

Os gerenciadores de recursos voláteis não podem recuperar de falhas para concluir uma transação na qual estavam participando.Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. Para obter uma inscrição durável em uma transação, use o método EnlistDurable.To obtain a durable enlistment in a transaction, use the EnlistDurable method.

Os gerenciadores de recursos inscritos para a participação em uma transação por esse método recebem duas notificações de confirmação de fase que correspondem aos métodos definidos na interface IEnlistmentNotification.Resource managers enlisted for participation in a transaction through this method receive two phase commit notifications that correspond to the methods defined on the IEnlistmentNotification interface.

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Inscreve um Resource Manager volátil que dá suporte à otimização em fase única para participar de uma transação.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 ^ notification, System::Transactions::EnlistmentOptions options);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.ISinglePhaseNotification singlePhaseNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.ISinglePhaseNotification notification, System.Transactions.EnlistmentOptions options);
member this.EnlistVolatile : System.Transactions.ISinglePhaseNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
member this.EnlistVolatile : System.Transactions.ISinglePhaseNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (singlePhaseNotification As ISinglePhaseNotification, enlistmentOptions As EnlistmentOptions) As Enlistment
Public Function EnlistVolatile (notification As ISinglePhaseNotification, options As EnlistmentOptions) As Enlistment

Parameters

singlePhaseNotificationnotification
ISinglePhaseNotification

Um objeto que implementa a interface ISinglePhaseNotification, a qual deve ser capaz de receber notificações de confirmação em uma e em duas fases.An object that implements the ISinglePhaseNotification interface that must be able to receive single phase commit and two phase commit notifications.

enlistmentOptionsoptions
EnlistmentOptions

EnlistDuringPrepareRequired se o gerenciador de recursos desejar realizar trabalho adicional durante a fase de preparação.EnlistDuringPrepareRequired if the resource manager wants to perform additional work during the prepare phase.

Returns

Enlistment

Um objeto Enlistment que descreve a inscrição.An Enlistment object that describes the enlistment.

Remarks

Os gerenciadores de recursos voláteis não podem recuperar de falhas para concluir uma transação na qual estavam participando.Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. Para obter uma inscrição durável em uma transação, use o método EnlistDurable.To obtain a durable enlistment in a transaction, use the EnlistDurable method. Para obter mais informações sobre os recursos voláteis e duráveis, bem como para inscrever um recurso, consulte implementando um Gerenciador de recursos.For more information on volatile and durable resources, as well as how to enlist a resource, see Implementing A Resource Manager. Para obter mais informações sobre como um Gerenciador de recursos responde à notificação de confirmação e à preparação da confirmação, consulte confirmando uma transação em fase única e várias fases.For more information on how a resource manager responds to commit notification and prepare the commit, see Committing A Transaction In Single-Phase and Multi-Phase.

Você deve observar que mesmo quando a implementação do Resource Manager se registrar com esse método, não há garantia de que ele receba uma única confirmação de fase.You should note that even when your resource manager implementation enlists with this method, it is not guaranteed that it receives a single phase commit. Em vez disso, o Gerenciador de transações ainda pode enviar duas notificações de confirmação de fase.The transaction manager can still send two phase commit notifications instead. Para obter mais informações sobre a otimização de confirmação de fase única, consulte otimização usando confirmação de fase única e notificação de fase única de promoçãotable.For more information on the single phase commit optimization, see Optimization Using Single Phase Commit and Promotable Single Phase Notification.

See also

Applies to