How are you creating the events? In the form? If you might be able to override Dispose in the form to unload your reactor
Because I want to share data between drawings from within the form, I can't just create a new form in each drawingYes you can.
Hi,
Maybe I misunderstand the issue but, according it seems to me it's safer to always dispose a modal dialog after used, you can get the data from properties of the instance of dialog and store them as static members in the class containing the CommandMethod so that they're accessible between drawings.
I would try this, this way the form owns the reactor
Yes you can.Ok, so I'm not actually storing data between drawings. I am manipulating data across several drawings. Nearly everything is built as a palette. Opening, closing or activating a drawing should force the application to read certain data from the current drawing and display it with the option of putting it into another drawing, or as in the case of one function, changing a value of an attribute in one drawing will prompt an update in another open drawing provided certain criteria are met.
If you want the data to be stored in the Form class, you can expose them as static properties and from the Command side just show the dialog to edit the data.
[
The problem is that when the form is disposed, the event handler remains active. I determined this by grabbing the handle of the window on close. After disposing the form, and reinitializing a new one, the event handler gave me the handle to the disposed form, not the current form, despite the form being disposed AND the error handler being defined in the form.
Class
{
Class()
{
Load reactor
}
~Class()
{
Unload reactor
}
}
Herein lies the problem. If the form gets disposed somehow (it happens occasionally, still working on that) and I instantiate a new one, it will work fine in the current drawing, but if I open a new drawing or switch to a different drawing, the DocumentBecameCurrent event fires from the disposed form and crashes AutoCAD because everything has been disposed.I think you meant to say "the DocumentBecameCurrent event handler fires from the disposed form"
The problem is that when the form is disposed, the event handler remains active. I determined this by grabbing the handle of the window on close. <snip>Again, the 'event dispatcher' remains active, the 'event handler' went with the disposed form.
After disposing the form, and re-initializing a new one, the event handler gave me the handle to the disposed form, not the current form, despite the form being disposed AND the error handler being defined in the form.Again, replace event handler with dispatcher...
Ultimately I think the issue is that once you define a variable in a static class, those variables apparently do not go out of scope just because the form holding them is disposed. It is working now though.That's right, the variable can't go out of scope until the class that contains it does BUT the variable can become null when the form that was referenced by that variable becomes null (disposed).