myDialog d = new myDialog();
d.ShowDialog();
Once my dialog processes some input, I do a
this.Close();
from within the dialog class.
then back in my main window, I check a variable i.e.
if (d.OK = true)
{
//do stuff
}
Is this ok if several of these dialogs will be created as the program is used? Or should I use a static variable on my main form that references the same dialog? Does it make a difference?
Use this pattern and your dialog will always be correctly disposed
Using a static variable to maintain the dialog from disposing (and in that case you should call
this.Hide()notthis.Close()is, in my opinion, a bad practice, unless you need to keep track of a ‘state condition’ or propose to your users their last inputs. You should also be very carefull in closing the static variable when you app close.