@bakerrWZ69Z wrote:
Then why is OpenCloseTransaction derived off of Transaction and why is a transaction manager used to create it?
OpenCloseTransaction derives from Transaction so that it looks like a Transaction, and can be used interchangeably with code that uses any Transaction (with the exception of the TransactionManager property). I have hundreds of APIs that take a Transaction as an argument. I can pass them either type of transaction (depending on the use case and context), and they will work with either type of transaction passed to them.
If OpenCloseTransaction wasn't derived from Transaction, you would have to write different code to work with it.
It seems to me that when the transaction manager StartOpenCloseTransaction method was used to create the OpenCloseTransaction it failed to initialize the TransactionManager read-only property.
It isn't failing to initialize the TransactionManager property. TransactionManagers are database-specific. Every Database has a TransactionManager, and every TransactionManager is owned by a single Database.
OpenCloseTransactions are not database-specific, which is why there is no TransactionManager.
Here is the source code for StartOpenCloseTransaction():
// Acdbmgd, Version=25.0.0.0, Culture=neutral, PublicKeyToken=null
// Autodesk.AutoCAD.DatabaseServices.TransactionManager
public virtual OpenCloseTransaction StartOpenCloseTransaction()
{
return new OpenCloseTransaction();
}
As we can see, all it does is call the constructor for OpenCloseTransaction, and doesn't pass it any arguments.
I routinely use OpenCloseTransactions by calling the constructor just as the method above does. I can't remember the last time I called StartOpenCloseTransaction(). There's no point to it, since all it does is call the constructor.
That works, because an OpenCloseTransaction is not associated with any database, and in fact, you can use the same OpenCloseTransaction to open DBObjects from different databases. An OpenCloseTransaction is functionally like a List<DBObject> that contains open DBObjects that you got by calling GetObject(). When you call Commit(), it calls Close() on each open DBObject in the list. When you call Abort(), it calls Cancel() on each open DBObject in the list. Dispose() calls Abort(), and that's about all there is to it.
Still my main questions is: Can I ignore the exception message?
Even though I have a catch that will catch a Autodesk.AutoCAD.Runtime.Exception it never executes my catch code so I am assuming the exception is being caught somewhere else.
It depends on what you're using the TransactionManager property for. With an OpenCloseTransaction, there is no TransactionManager, so I can't really tell you how to deal with that without knowing why you need to use the TransactionManager. As far as catching the exception it throws, I don't know what good that would be if your code subsequently needs to use the TransactionManager.