This documentation is archived and is not being maintained.

PreparingEnlistment.Prepared Method

Indicates that the transaction can be committed.

Namespace:  System.Transactions
Assembly:  System.Transactions (in System.Transactions.dll)

'Declaration
Public Sub Prepared
'Usage
Dim instance As PreparingEnlistment

instance.Prepared()

In the first (prepare) phase of a two phase commit, a resource manager implementing the Prepare method of the IEnlistmentNotification interface, calls this method to indicate that the transaction can be committed.

The resource manager can call the Done method at anytime before it has called this method. By doing so, the enlistment is casting a read only vote, meaning that it votes commit on the transaction but does not need to receive the final outcome.

Once this method is called by an enlistment and before it returns, it is possible that another thread or this same thread could make a call into the same enlistment method such as Rollback to perform a rollback. This can result in a deadlock situation if the resource manager implementation does not release resource locks until after this method returns.

	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
	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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: