• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    *Maksim Sestic

    Opening objects ForRead but not closing them?

    44 Views, 2 Replies
    08-11-2005 05:04 AM

    Dear All,

     

    I'm a bit confused about what ObjectARX DevGuide
    is suggesting and what happens in real life. It's about opening objects with
    OpenMode.ForRead using TransactionManager - do I need to imlicitly Close()
    opened object after I'm finished inspecting it, or it's performed somehow
    automatically when current Transaction gets disposed? Here's what ObjectARX
    DevGuide suggests:

     

    Obtaining Pointers to Objects in a Transaction

    (...)

    If you use the getObject() function to obtain an
    object pointer, you should never call close() on that
    object pointer. Calling close() is valid only if you
    obtained the pointer using acdbOpenObject() or the
    object was newly created. For more information on when you can call
    class=courier>close()
    on an object pointer, see the following sections,

    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxdev188...
    and
    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxdev181...

     

    and also:

     



    title="Mixing the Transaction Model with the Open and Close Mechanism ">Mixing
    the Transaction Model with the Open and Close Mechanism


    title="Mixing the Transaction Model with the Open and Close Mechanism ">The
    transaction model coexists with the regular open and close mechanism described
    in
    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxdev051...
    chapter
    5,
    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxdev05....
    However, if you are using the transaction model, it is recommended
    that you do not mix it with the open and close mechanism. For example, if you
    obtained a pointer to an object using
    class=courier>AcTransaction::getObject()
    , you should
    not call close() on
    the object pointer, which could cause unexpected results and may crash AutoCAD.
    However, you are free to open and close a particular object even if transactions
    are active. You can also instantiate new objects, add them to the database, and
    close them while transactions are active. The primary purpose of having the
    mixed model is to allow simultaneous execution of multiple applications where
    some use transaction management and others do not, but all of them are operating
    on the same objects.


    title="Mixing the Transaction Model with the Open and Close Mechanism "> 


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face=Verdana size=2>What really happens sometimes is that ACAD clugs and crashes
    if I do not issue implicit Close() of an object. Here's a simple piece of code
    utilizing above stated mechanism (sticking to DevGuide directives):


    title="Mixing the Transaction Model with the Open and Close Mechanism "> 


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New">Dim db
    As Database =
    Application.DocumentManager.MdiActiveDocument.Database()


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New">Dim trm
    As
    Autodesk.AutoCAD.DatabaseServices.TransactionManager =
    db.TransactionManager


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New">Dim tr
    As Transaction =
    trm.StartTransaction


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New">Dim bt
    As BlockTable =
    tr.GetObject(db.BlockTableId, OpenMode.ForRead)


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" size=2>
     


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" color=#0000ff size=2>Try


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New">   For
    size=2>
    Each ob
    As ObjectId
    color=#0000ff size=2>In
    bt


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New">     
    Dim
    btr As
    size=2> BlockTableRecord = tr.GetObject(ob,
    OpenMode.ForRead)


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New">  
    color=#0000ff>    If
    UCase(btr.Name) = btr.ModelSpace
    Then


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    color=#0000ff>
    size=2>        
    color=#008080>'Inspect some ModelSpace properties...


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    size=2>
    color=#0000ff>      End

    color=#0000ff>If


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    color=#0000ff>  
    face="Courier New" size=2>Next


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    size=2>
    color=#0000ff>Finally


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" size=2>

    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" size=2>   bt.Dispose()
      
    tr.Dispose()


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" size=2>   trm.Dispose()


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" size=2>

    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" color=#0000ff size=2>

    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face="Courier New" color=#000000 size=2>  
    db.Dispose()
    End Try


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    color=#0000ff>
     


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face=Verdana>Thanks in advance for any suggestion or clarification.


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face=Verdana>
     


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face=Verdana>Regards,


    title="Mixing the Transaction Model with the Open and Close Mechanism ">
    face=Verdana>Maksim Sestic
    Please use plain text.
    *Maksim Sestic

    Re: Opening objects ForRead but not closing them?

    08-12-2005 05:33 AM in reply to: *Maksim Sestic

    Final conclusions... There is an error either in
    .NET wrapper regarding TransactionManager behaviour, or in ObjectARX DevGuide.
    Please note the statement from a full excerpt below:

     

    "If you use the getObject() function to obtain
    an object pointer, you should never call close() on
    that object pointer."

     

    What really happens is that ACAD crashes during
    shutdown (Quit) if there is no Close() for obained object pointers
    within Transaction. It's of no significance if object is opened ForRead or
    ForWrite.

     

    Regards,

    Maksim Sestic

     

     

    Obtaining Pointers to Objects in a Transaction


    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

    (...)

    If you use the getObject() function to obtain
    an object pointer, you should never call close() on
    that object pointer. Calling close() is valid only
    if you obtained the pointer using acdbOpenObject()
    or the object was newly created. For more information on when you can call
    close() on an object pointer, see the following
    sections,
    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxdev1...
    and
    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxdev1...

    Please use plain text.
    *Albert Szilvasy

    Re: Opening objects ForRead but not closing them?

    08-28-2005 05:23 PM in reply to: *Maksim Sestic

    Can you post some code that shows this behavior?
    This shouldn't happen so I'm pretty sure there's something else going
    on.

     

    ALbert


    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


    Final conclusions... There is an error either
    in .NET wrapper regarding TransactionManager behaviour, or in ObjectARX
    DevGuide. Please note the statement from a full excerpt below:

     

    "If you use the getObject() function to obtain
    an object pointer, you should never call close() on
    that object pointer."

     

    What really happens is that ACAD crashes during
    shutdown (Quit) if there is no Close() for obained object pointers
    within Transaction. It's of no significance if object is opened ForRead
    or ForWrite.

     

    Regards,

    Maksim Sestic

     

     

    Obtaining Pointers to Objects in a Transaction


    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

    (...)

    If you use the getObject() function to
    obtain an object pointer, you should never call
    class=courier>close()
    on that object pointer. Calling
    class=courier>close()
    is valid only if you obtained the pointer using
    acdbOpenObject() or the object was newly created.
    For more information on when you can call close()
    on an object pointer, see the following sections,
    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxde...
    and
    href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\Desktop\docs\arxdev.chm::/arxde...

    Please use plain text.