473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Form won't stay away...

Tim
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();
Nov 17 '05 #1
1 1111
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();

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Julia Baresch | last post by:
Hi everyone, As some of you may know, we've been having trouble with an unrecognized database format error. Today I installed an unfinished project on the workstation of one of my users. ...
7
by: sara | last post by:
I guess this is simple, but I'm stuck. I am trying to write a simple app - Newspapers and their circulation by town. tables: tblPaper - ID (autonum, key) and Newspaper (indexed) tblTown - ID...
3
by: MrNobody | last post by:
I'm pretty tired from working all day on this program and this one simple task of showing a certain form when the app initializes is driving me nuts... It opens very briefly then quickly...
5
by: MrNobody | last post by:
I am using the no-arg ShowDialog() method hoping that the window would not be modal to any other window like the other ShowDialog(IWin32Window) method does, but when this opens it somehow becomes...
3
by: Tim | last post by:
Hi, I have have a program containing two forms that are open at the same time. The main form updates the second when the user enters input by adding a control to it. My problem is that when the...
5
by: Lance Colton | last post by:
it only behaves as expected if i edit the service to run under the system account and enable the "allow service to interact with desktop" option. if i run without that enabled or run it under my...
4
by: kaosyeti | last post by:
what's the best way to get a form to always open at a specific size. i've sized and saved the forms, changed the borders and had popup on and off all over but can't seem to get it to stay one way...
8
by: Peter Pippinger | last post by:
Hello NG, i have done some work in c#. But now i want to learn c++. I cant find out, how to use strings. in c# i have a function: public void info(string nachricht) {...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.