.NET

.NET

Reply
Contributor
autogis
Posts: 19
Registered: ‎11-13-2013
Message 1 of 5 (209 Views)

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

209 Views, 4 Replies
05-15-2014 07:30 AM

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

Distinguished Contributor
mcicognani
Posts: 131
Registered: ‎12-01-2004
Message 2 of 5 (199 Views)

Re: Difference between db...StartTransaction and doc...StartTransaction

05-15-2014 07:56 AM 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...

ADN Support Specialist
Virupaksha.aithal
Posts: 102
Registered: ‎06-15-2011
Message 3 of 5 (116 Views)

Re: Difference between db...StartTransaction and doc...StartTransaction

05-28-2014 12:06 AM in reply to: mcicognani

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

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 4 of 5 (108 Views)

Re: Difference between db...StartTransaction and doc...StartTransaction

05-28-2014 05:21 AM 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
Distinguished Contributor
mcicognani
Posts: 131
Registered: ‎12-01-2004
Message 5 of 5 (105 Views)

Re: Difference between db...StartTransaction and doc...StartTransaction

05-28-2014 05:25 AM in reply to: jeff

Good to know Jeff!

 

Thank you, you deserve a kudo!

 

Massimo

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.