ILinkedUndoContext::BeginTransaction Method (String^)

 

Group a series of changes to the model. If any change fails, you can abort the whole group, leaving the model unchanged. Call Commit() to complete the transaction. If the user calls undo, the whole group will be rolled back.

Namespace:   Microsoft.VisualStudio.Modeling.ExtensionEnablement
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)

ILinkedUndoTransaction^ BeginTransaction(
	String^ description
)

Parameters

description
Type: System::String^

Any string that identifies the transaction.

Return Value

Type: Microsoft.VisualStudio.Modeling.ExtensionEnablement::ILinkedUndoTransaction^

The new transaction. When your changes are complete, Commit or Abort, and dispose this transaction.

Perform this operation in the initializer of a using clause, to ensure that the transaction is disposed when you have finished your changes.

An exception that is not caught inside the using block will cause all the UML model changes inside it to be rolled back. Note that this applies only to changes on the UML model, and not to changes that have been made to other variables, external databases, files, and so on.

Transactions can be nested.

For more information, see Link UML model updates by using transactions.

try
{
  using (ILinkedUndoTransaction transaction =
              LinkedUndoContext.BeginTransaction("Swap names"))
  { 
    Operation1(); 
    Operation2();
    // Any exception in the preceding statements
    // will undo all of the changes in the model.
    transaction.Commit(); // Always remember Commit()!
  }
}
catch ()
{
    // If control reaches here,
    // Operation1 and Operation2 have
    // made no change to the model.
}
Return to top
Show: