Hi there I am new to this forum so hi to every one.
I have a problem with an application I am developing an application.
The application is suppose to call a form.showdialog() method to show
the form. Th eform should download a package. But the problem is that
when I cancel the download and try to see a property IsDownloadComplete
it says the object is disposed. How can I read a property from that
form?
thanking in anticipation
Loading
AlanPosted Aug 3, 2008, 9:08 AM
In an attempt to model it as simply as possible, I've just quickly created an app with two forms. The start up form has a button and a label. When the button is pressed, Form2 opens up.
The second (modal) form just has a button which when pressed toggles a property.
Here's the code:
public
partial class Form1 : Form{
private Form2 f2; public Form1(){
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e){
DialogResult dr = f2.ShowDialog(); if (dr == DialogResult.Cancel){
this.label1.Text = f2.IsButtonPressed.ToString();}
}
private void Form1_Load(object sender, EventArgs e){
f2 =
new Form2();}
}
public
partial class Form2 : Form{
public Form2(){
InitializeComponent();
}
public bool IsButtonPressed = false; private void button1_Click(object sender, EventArgs e){
IsButtonPressed = !IsButtonPressed;
}
}
When the app is run and the Close button on Form2 is clicked (thereby returning a DialogResult of cancel), the label on Form1 reflects the current state of the property no matter how many times Form2 is opened. An 'accessing a disposed object' exception is never thrown.
Can you see any essential difference in inter-form communication between your app and this ?
Umair PPosted Aug 3, 2008, 7:45 AM
AlanPosted Aug 3, 2008, 7:42 AM
Are you sure that it's the 'objDownLoad' form that's been disposed of and not some other object on that form which is accessed by the IsDownloadComplete property?
Umair PPosted Aug 3, 2008, 6:06 AM
{
objDownload.ShowDialog();// here is the problem. it tries to access the obj that is already dead.
if (objDownload.IsDownloadCompleted)
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
//System.Windows.Forms.MessageBox.Show(" MY Message ");
return false;
}
above is the code where debugger shows error
there is nothing in the form_close() event.
Note: I am using cancel button.
AlanPosted Aug 3, 2008, 5:59 AM
When you open a form modally by calling its ShowDialog() method then, even if you click the Close button, the form instance is not actually disposed of - it's just hidden.
So, if the IsDownloadComplete property is on the modal form, then it should still be callable unless you've manually called the Dispose() method somewhere, such as from the FormClosed eventhandler.
I'd therefore check your code to see whether or not this is the case.