Terminating an Automatic Transaction by Calling SetComplete

To use automatic transactions effectively, each transactional component should indicate that it has completed its work. When an object instance completes its task successfully, it should set its consistent and done flags to True by calling the IObjectContext::SetComplete method, which is exposed through both the IObjectContext interface and the ObjectContext object.

The most efficient way to complete an automatic transaction is to explicitly deactivate the root object by using the SetComplete method. By explicitly indicating that a root object has completed its work, you can reduce the length of the transaction.

The following Visual Basic example shows how to indicate that a transactional object has completed its work successfully:

Sub MyObjMethod1()
  Dim ObjCtx As ObjectContext
  Dim InteriorObj1 As Cinterior  ' Cinterior is a user-defined object.

  Set ObjCtx = GetObjectContext()
  Set InteriorObj1 = CreateObject ("MyDll.Cinterior")
  InteriorObj1.Method1
  ' If the call completed successfully, then...
  objCtx.SetComplete
End Sub

Consistent and Done Flags

Managing Automatic Transactions in COM+