The code I originally had below in the Duplicate Mark sample works fine when everything goes according to plan. But a more robust approach would use a “using” block as shown below.
using( Transaction transaction = new Transaction(document,"action") )
{
transaction.Start();
// ....
transaction.Commit();
}
This goes for every transaction as well as every transaction group and sub-transaction. The objective is to make sure those objects are properly closed (particularly in case of an exception). More on the subject is in the MSDN C# reference.
[…] is used to make sure that “disposable” things like transactions are correctly handled https://boostyourbim.wordpress.com/2012/12/04/use-a-using-block-with-transactions/ […]