Hi gentlemen, see 2 functions below please. Which one is right ? Shall I commit Transaction or Not? I don't get any error at all in both cases but like to know what is right.
Function Test() as Boolean Using tr As Transaction = Mydwg.TransactionManager.StartTransaction If BlahBlah = BlahBlahBlah Then Return True End If tr.Commit() End Using Return False End Function Function Test1() as Boolean Using tr As Transaction = Mydwg.TransactionManager.StartTransaction If BlahBlah = BlahBlahBlah Then tr.commit Return True End If tr.Commit() End Using Return False End Function
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
Hopefully, there is something else going on inside your If block, or you don't need the transaction at all. That said, in function Test, if BlahBlah = BlahBlahBlah then the transaction will not be committed, because the function returns before hitting the commit. The only way you could not notice this in your real code is if the transaction is read only (or if you really don't need the transaction at all), otherwise you would see that whatever changes your code made were reverted. Read-Only transactions should always be committed, because if you do not call commit, then when the transaction is disposed (at your End Using) tr.Abort is automatically called, and tr.Abort carries more overhead than tr.commit.
Thank you very much for explanation , I go with Test1 function then.
Cheers.
Janet.