Tim,
Are you running this in an event handler for a control? If so, it is
possible that an exception is being thrown, which is preventing the Dispose
method from being called, and leaving the instance hanging around.
In order to get around this, you should code it like this:
using (MM.Forms.frmPriceCalc fCalc = new MM.Forms.frmPriceCalc())
{
fCalc.RegPriceCalc = true; //regular price
fCalc.calcSource = 2;
fCalc.LoadFormInfo();
if(fCalc.ShowDialog(this) == DialogResult.OK)
{
//price has changed refresh the grid.
GridDataPreload();
}
}
This way, if an exception is thrown, you will dispose of the form
properly.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Tim" <ti*@home.com> wrote in message
news:xj*******************@news20.bellglobal.com.. .
Hi
I have the following code to open a form modally. It works great only the
second time I have to close it twice, the third time 4 times.
I am using Dispose(), why is it coming back so much?
Tim
MM.Forms.frmPriceCalc fCalc = new MM.Forms.frmPriceCalc();
fCalc.RegPriceCalc = true; //regular price
fCalc.calcSource = 2;
fCalc.LoadFormInfo();
if(fCalc.ShowDialog(this) == DialogResult.OK)
{
//price has changed refresh the grid.
GridDataPreload();
}
fCalc.Dispose();