.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difference between db...StartTransaction and doc...StartTransaction

4 REPLIES 4
Reply
Message 1 of 5
autogis
516 Views, 4 Replies

Difference between db...StartTransaction and doc...StartTransaction

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

4 REPLIES 4
Message 2 of 5
mcicognani
in reply to: autogis

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...

Message 3 of 5

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.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 4 of 5
jeff
in reply to: Virupaksha_aithal

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
 

 

You can also find your answers @ TheSwamp
Message 5 of 5
mcicognani
in reply to: jeff

Good to know Jeff!

 

Thank you, you deserve a kudo!

 

Massimo

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost