Transaction.EnlistVolatile Method (IEnlistmentNotification, EnlistmentOptions)
Enlists a volatile resource manager that supports two phase commit to participate in a transaction.
Assembly: System.Transactions (in System.Transactions.dll)
'Declaration Public Function EnlistVolatile ( _ enlistmentNotification As IEnlistmentNotification, _ enlistmentOptions As EnlistmentOptions _ ) As Enlistment
- Type: System.Transactions.IEnlistmentNotification
An object that implements the IEnlistmentNotification interface to receive two phase commit notifications.
Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. To obtain a durable enlistment in a transaction, use the EnlistDurable method. For more information on volatile and durable resources, as well as how to enlist a resource, see Implementing A Resource Manager. 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.
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.
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.
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
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.