Is it safe to use Database in the Initialize() method?

Is it safe to use Database in the Initialize() method?

Anonymous
Not applicable
597 Views
1 Reply
Message 1 of 2

Is it safe to use Database in the Initialize() method?

Anonymous
Not applicable

When I do it, then my code looks something like this:

 

public void Initialize() {
  Document doc = cad.DocumentManager.MdiActiveDocument;
  if (null == doc)
    return;
 
  Database db = doc.Database;
  Editor ed = doc.Editor;
 
  using (doc.LockDocument()) {
    using (Transaction tr = db.TransactionManager.StartTransaction()) {
      ed.WriteMessage("\nThe \"{0}\" assembly successfully loaded.\n",
        this.GetType().Assembly.Location);      
      // TODO: Here is my code of working with Database...
      tr.Commit();
    }
  }
}


Assembly can be registered for autoloading (through the registry record or BUNDLE engine). I hadn't problems with such approach, but I remember - Alexander Rivilis wrote he had. He wrote what the Document (or Database) can be initialized not completely at the time of operation of this code. Ok, how can I check initialization of these objects was finished?

0 Likes
Accepted solutions (1)
598 Views
1 Reply
Reply (1)
Message 2 of 2

max.senft
Enthusiast
Enthusiast
Accepted solution

Hi,

 

it seems this matches your "problem": http://through-the-interface.typepad.com/through_the_interface/2013/01/displaying-a-dialog-on-autoca... Smiley Indifferent

 

At least in the introduction Kean wrote the sentence: "[...]he needed to display a dialog on AutoCAD startup, but found that it was too soon to do so on IExtentionApplication.Initialize()[...]".

 

Regards

Max

0 Likes