Export (0) Print
Expand All

Enlistment Class

Facilitates communication between an enlisted transaction participant and the transaction manager during the final phase of the transaction.

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

'Declaration
Public Class Enlistment

The Enlistment type exposes the following members.

  NameDescription
Public methodDoneIndicates that the transaction participant has completed its work.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

When the EnlistVolatile and EnlistDurable methods of the Transaction object are invoked to enlist a participant in a transaction, they return this object describing the enlistment.

During the final phase of the transaction commit, the transaction manager passes this object to a resource manager implementing the IEnlistmentNotification interface that has enlisted in a transaction. Specifically, the transaction manager calls either the Commit or the Rollback method of the participant, depending on whether the latter has decided to commit or roll back the transaction. The participant should call the Done method of this object to let the transaction manager know that it has completed its work.

An enlistment can call the Done method at anytime before it has called Prepared in the prepare phase. 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. Note that, after the Done method is called, the enlisted participant receives no further notifications from the transaction manager.

The following example shows an implementation of the IEnlistmentNotification interface, and when the Done method should be called.

	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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

This type is thread safe.

Show:
© 2014 Microsoft