I see no reason to not also nest the read-only
operations in the lock scope, for the sake of
clarity.
Also, you can dispense with one pair of curly
braces when you have two using() clauses
with the same scope, like this:
public void singleblock()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
DocumentLock doclock = doc.LockDocument();
Transaction trans = doc.TransactionManager.StartTransaction();
using( doclock )
using( trans )
{
// Do stuff here
}
}
which is precisely equivlent to:
public void multipleblock()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
using( DocumentLock doclock = doc.LockDocument() )
{
using( Transaction trans = doc.TransactionManager.StartTransaction() )
{
// Do stuff here
}
}
}
that works because using() is like many other
constructs that can precede either a single line
of code, or a block of code:
if( test )
{
then();
}
verses
if( test )
then();
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
"Paul Richardson"
wrote in message news:5499519@discussion.autodesk.com...
Is this nested properly?
[code]
using (Transaction tr = ed.Document.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId,
OpenMode.ForRead);
ObjectId blkRecId = bt[BlockTableRecord.ModelSpace];
using (DocumentLock myLock = newDoc.LockDocument())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRecId,
OpenMode.ForWrite);
btr.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
}
tr.Commit();
}
[/code]
"Tony Tanzillo" wrote in message
news:5499486@discussion.autodesk.com...
>> newDoc.LockDocument();
The result of LockDocument() must be
Disposed() of explicitly, because that is
what unlocks the document.
If you let the runtime do it (e.g., whenever
it gets around to it), the document remains
locked until that happens.
So,
using( DocumentLock myLock = newDoc.LockDocument() )
{
// work with locked document here
} // document is unlocked here
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
"Paul Richardson" wrote in message
news:5499364@discussion.autodesk.com...
CommandFlags.Session -> makes the command available in the application
context
instead of just the calling doc.
newDoc.LockDocument ->Before you edit a doc you must lock it. When an app
runs
in the doc context the doc is locked for you. Others must be locked
manually.
Attached is a sample of a test. Keyword test!
wrote in message news:5499346@discussion.autodesk.com...
Thank you,Palul.
What I can clear. ---> Adding commandFlags.Session,
newDoc is activated to the current drawing.
What I can get. --->I don't know what change was made with using
method of newDoc.LockDocument.