PreparingEnlistment Class

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

System.Object
  System.Transactions.Enlistment
    System.Transactions.PreparingEnlistment

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

public class PreparingEnlistment : Enlistment

The PreparingEnlistment type exposes the following members.

  NameDescription
Public methodDoneIndicates that the transaction participant has completed its work. (Inherited from Enlistment.)
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 methodForceRollback()Indicates that the transaction should be rolled back.
Public methodForceRollback(Exception)Indicates that the transaction should be rolled back.
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 methodPreparedIndicates that the transaction can be committed.
Public methodRecoveryInformationGets the recovery information of an enlistment.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

During the initial (prepare) phase of the transaction, the transaction manager passes this type to the resource manager by calling the Prepare method to obtain a resource's vote on the transaction. Depending on whether it votes to commit or roll back, your implementation of the resource manager should call the Prepared or ForceRollback methods of this type.

The resource manager can also call the Done method at anytime before it has called the Prepared 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.

Durable resource managers can retrieve the information that is be needed by the transaction manager for re-enlistment from the RecoveryInformation property. For more information on recovery, see Performing Recovery.

		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();
			}
		}

.NET Framework

Supported in: 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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft