using (doc.LockDocument())
{
.....
}
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
DocumentLock loc = doc.LockDocument();
....
loc.Dispose();
DocumentLock loc = doc.LockDocument();
then you are to use 'try\catch\finally' block and unlock document in the 'finally' block.try { db.LoadLineTypeFile(clType, cLinFile); }
catch { }
DocumentLock loc = doc.LockDocument();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBObjectCollection objs = new DBObjectCollection();
BlockReference br = tr.GetObject(blkId, OpenMode.ForWrite) as BlockReference;
.....
using (doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBObjectCollection objs = new DBObjectCollection();
BlockReference br = tr.GetObject(blkId, OpenMode.ForWrite) as BlockReference;
....
}
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
using (doc.LockDocument())
{
DBObjectCollection objs = new DBObjectCollection();
BlockReference br = tr.GetObject(blkId, OpenMode.ForWrite) as BlockReference;
....
}
}
should I declare using (doc.LockDocument()) inside or outside using (Transaction tr = db.TransactionManager.StartTransaction()) ?I think both variants are correct.
I thought "finally" was useless if there was nothing to be done in the catch.Content of the finally block will be called always. Content of the catch block will be called only if exception occurs. Read about the finally in the C# specification, please.
Hi,
By my side I use to write :Code - C#: [Select]
using (doc.LockDocument()) using (var tr = db.TransactionManager.StartTransaction()) { // ... } // <- the transaction is disposed, then the document is unlocked (disposed)