There's actually nothing wrong with it now, but I think in
earlier releases, the dispose implementation didn't care
if the database was open in AutoCAD or not. Since I do
not always know what release someone may be using,
I generally advise to avoid it on databases that are open
in the editor.
Dispose can be safely called on most objects, since some
of them do nothing when it's called. The downside of doing
that is that code can become much more complicated.
But, one still cannot follow a general rule that you can/should
call Dispose() on anything that implements IDisposable (an
example is the Document object).
The problem we have with this API design, is that out of little
other than serving the convenience of the API developer,
almost all managed types derive from DisposableWrapper,
meaning they all implement IDisposable, without regard for
whether there is actually a need for it. The other problem with
the design is that in some cases, failing to call Dispose() can
be fatal.
Sorry to say it, but that's just a horrifyingly bad design
if you ask me, to wit the massive confusion we've seen
here from so many (expressed outright, and implied by
the code they post).
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com
Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
"Kerry Brown" wrote in message
news:6211722@discussion.autodesk.com...
Bobby,
why are you 'using' this
using (Database db = HostApplicationServices.WorkingDatabase)
??
/// kdub
"Bobby C. Jones" wrote in message
news:6211430@discussion.autodesk.com...
When translating VB to C# remember that C# uses indexers. The VB
IList.Item(0) is IList[0] in C#.
You can also get rid of some nesting with this syntax:
using (DocumentLock lck = dwg.LockDocument())
using (Database db = HostApplicationServices.WorkingDatabase)
using (Transaction tr = db.TransactionManager.StartTransaction())
{
...
}
However, you really shouldn't call dispose on a database that you didn't
instantiate. Autodesk has assured us that the dispose method is coded to
protect us from disposing of a database that we shouldn't, but it's still
not a good practice.
--
Bobby C. Jones
http://bobbycjones.spaces.live.com