Author Topic: Closing and/or disposing forms in context of CommandFlags.Session  (Read 1851 times)

0 Members and 1 Guest are viewing this topic.

AIYOUNG

  • Guest
Hello all,

I was wondering if anyone could explain if the behavior closing or disposing a form is different when using commandflags.session in a project.

I'm working on porting a legacy project from VBA to VB.NET for work.

Part of the legacy code uses thisdrawing.SendCommand to invoke lisp code, so i have to use commandflags.session so that SendCommand is completed synchronously.

Some text fields in a form in the project are filled using data from the currently activated document.

I noticed that when i close my form, switch to a new drawing, then re-invoke my code, the form text isn't properly updated.

I'm a total newbie at developing for AutoCAD  here so i apologize if I've butchered, miss-used, or misinterpreted any of the terminology i used in this post!


n.yuan

  • Bull Frog
  • Posts: 347
Re: Closing and/or disposing forms in context of CommandFlags.Session
« Reply #1 on: April 09, 2014, 09:33:49 AM »
Controls on the form not being updated properly may not have anything to do with your command being in session context or not.

How do you instantiate the form? From the static command method or non-static command method? How the form is opened (as modal or modeless)? How do you close/dispose the form? It is really difficult to suggest anything without seeing all the relevant code.

AIYOUNG

  • Guest
Re: Closing and/or disposing forms in context of CommandFlags.Session
« Reply #2 on: April 09, 2014, 10:11:30 AM »
Thanks for the reply!

The form is opened as modal as myForm.ShowDialog() and is closed using myForm.close().

I might attempt to make an example code that recreates what i am seeing. If i do i will post it here.

The code i am working on converting is gigantic and proprietary so i can't go posting the source in a public forum.


n.yuan

  • Bull Frog
  • Posts: 347
Re: Closing and/or disposing forms in context of CommandFlags.Session
« Reply #3 on: April 09, 2014, 12:33:35 PM »
A few things:

1. You should not use Form.Show()/ShowDialog() to open/show a form in AutoCAD. Instead, use Application.ShowModalDialog()/ShowModelessDialog();

2. If the form is shown as modal dialog, Form.Close() DOES not dispose the form, it just sets the dialog form in invisible. When you call Form.Show()/ShowDialog() again, the hidden form simply becomes visible again, and the data on the form remain unchanged, unless you have code to update the form's data (you should!).

3. It is also important the command method that instantiates the form is static or not;

4. if your code involving a modal dialog form is gigantic, something is quite wrong (in term of code structure), unless you have a monstrous form with hundreds of controls on it (in this case, it may well also be wrong). You need to separate AutoCAD operation code from the Form's pure UI code.