.NET

.NET

Reply
Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 1 of 2 (182 Views)

Can you commit a Transaction within a Transaction?

182 Views, 1 Replies
08-15-2012 01:01 PM

Transactions -- Can you commit a Transaction within a Transaction without any problems? 

 

I have one transaction that cycles through all objects in drawing..

I have another transaction that purges all purgable objects. 

 

Can I call the Purge Function if I've already started a transaction? 

What's the proper protocol here? Does that make sense? 

 

  'Purge Database
        Dim count As Integer = PurgeDatabase(DatabaseIn)
        Debug.Print("Number of Items Purged: " & count)

        'Level 1 Start(Transaction/Drawing Database)-----------------------------------------------
        Using myTrans As Transaction = DatabaseIn.TransactionManager.StartTransaction 'Read Drawing Database

            'Level 2 Block Table------------------------------------------------------------
            Dim myBT As BlockTable = DatabaseIn.BlockTableId.GetObject(OpenMode.ForRead) 'Read BlockTable
            
            'Loop Through All Objects
            For Each myObjID As ObjectId In myBT 'Changed this line of code from myModelSpace

 

Private Function PurgeDatabase(ByVal DB As Database) As Integer
        Debug.Assert(DB IsNot Nothing, "DB is nothing.")

        Dim idCount As Integer = 0

        Dim tr As Transaction = DB.TransactionManager.StartTransaction

        Using tr
            'Create the list of objects to "purge"

 

Board Manager
StephenPreston
Posts: 377
Registered: ‎05-22-2006
Message 2 of 2 (173 Views)

Re: Can you commit a Transaction within a Transaction?

08-15-2012 01:34 PM in reply to: VB_Autocad_guy

In general, yes. You can use nested transactions and commit the inner transaction first. If you abort any transaction it should also roll back the committed transactions nested within it. The full operation will only be committed once the topmost transaction has been commited.

Cheers,

Stephen Preston
Autodesk Developer Network
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.