Another newbie question, when opening a dwg file, I noticed some examples start the transaction using the database and some with the document:
// Start Transaction
using (Transaction tr = db.TransactionManager.StartTransaction())
and
// Start Transaction
using (Transaction tr = doc.TransactionManager.StartTransaction())
What is the difference between each and when to use one or the other? And the other question is if I am opening a file read-only, do I still use tr.Commit() at the end?
Thanks Before Hand
To my knowledge the both access the same TransactionManager object, that is unique for each document. So no difference here (as far as I know).
For the committ(): if I recall correctly, the commit() should fail if the document is read only...
Hi,
yes, you will get same TransactionManager in both the ways.
if document is read-only, then you can not save the document. commit should work fine.
The Transactionmanger from Document is derived from the Database TransactionManager it adds a couple of methods FlushGraphics, EnableGraphicsFlush
It overrides StartTransaction to use a AppTransaction which derives from Transaction and it just overrides Commit which calls Transaction.Commit(Base.Commit) the calls FlushGraphics.
So basiclly only difference is the document transaction will help with graphic updating when commited.
internal sealed class AppTransaction : Transaction { // Fields private TransactionManager m_mgr; // Methods protected internal AppTransaction(IntPtr unmanagedPointer, [MarshalAs(UnmanagedType.U1)] bool autoDelete, TransactionManager mgr) : base(unmanagedPointer, autoDelete) { this.m_mgr = mgr; } public sealed override void Commit() { base.Commit(); ((TransactionManager) this.TransactionManager).FlushGraphics(); } // Properties public override TransactionManager TransactionManager { get { return this.m_mgr; } } } Collapse Methods