ObjectDisposedException on Form.Close()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am getting an ObjectDisposedException on closing a form and am at a loss as
to why it is happening. My understanding is that such an exception occurs
when an disposed object is referenced. However, I cannot identify where this
is happening. Below is the code:

private void lstPracs_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.lstPracs.SelectedValue.GetType() == typeof (Int16))
{
AttDetailsFrm frmAttDetails = (AttDetailsFrm)
FormMgr.Instance.OpenForm (Type.GetType
"CompTrackerPPC.AttDetailsFrm"));
frmAttDetails.PracId = (Int16)this.lstPracs.SelectedValue;
frmAttDetails.Show();
this.Close();
}
}

It seems the exception is raised after the above method exits.

Any suggestions would be greatly appreciated.

Ollie
 
More Info:

I do not get the exception if I close the form with out opening another
form. e.g.
private void cmdClose_Click(object sender, System.EventArgs e)
{
this.Close();
}

Also, it does not seem to matter which form I open, the exception is raised
as long as a form is opened before this form is closed.

Cheers,
Olivier
 
I seem to remember running into this before. My solution was to set a
timer, then close the window in the timer's event handler.

John
 
The problem is that you are trying to close the main form. Once main
form was closed the application exits. To solve your problem just replace:

this.Close();

with

this.Hide();

.... or follow Darren's suggestion to use ShowDialog instead.
 
Thanks to all for your suggestions.

I tryed using
frmAttDetails.ShowDialog();

but the ObjectDisposedException was still raised. I also confirmed that the
form that is being closed is not the main form. I have yet to try the timer
solution. I am still at a loss to determine why this ObjectDisposedException
is being raised in the first place.

Anymore feedback is greatly appreciatd,
Ollie

Sergey Bogdanov said:
The problem is that you are trying to close the main form. Once main
form was closed the application exits. To solve your problem just replace:

this.Close();

with

this.Hide();

.... or follow Darren's suggestion to use ShowDialog instead.


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I am getting an ObjectDisposedException on closing a form and am at a loss as
to why it is happening. My understanding is that such an exception occurs
when an disposed object is referenced. However, I cannot identify where this
is happening. Below is the code:

private void lstPracs_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.lstPracs.SelectedValue.GetType() == typeof (Int16))
{
AttDetailsFrm frmAttDetails = (AttDetailsFrm)
FormMgr.Instance.OpenForm (Type.GetType
"CompTrackerPPC.AttDetailsFrm"));
frmAttDetails.PracId = (Int16)this.lstPracs.SelectedValue;
frmAttDetails.Show();
this.Close();
}
}

It seems the exception is raised after the above method exits.

Any suggestions would be greatly appreciated.

Ollie
 
Okey, can you show us reproducible example of the issue? Or send it
directly to me.

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

Thanks to all for your suggestions.

I tryed using
frmAttDetails.ShowDialog();

but the ObjectDisposedException was still raised. I also confirmed that the
form that is being closed is not the main form. I have yet to try the timer
solution. I am still at a loss to determine why this ObjectDisposedException
is being raised in the first place.

Anymore feedback is greatly appreciatd,
Ollie

:

The problem is that you are trying to close the main form. Once main
form was closed the application exits. To solve your problem just replace:

this.Close();

with

this.Hide();

.... or follow Darren's suggestion to use ShowDialog instead.


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I am getting an ObjectDisposedException on closing a form and am at a loss as
to why it is happening. My understanding is that such an exception occurs
when an disposed object is referenced. However, I cannot identify where this
is happening. Below is the code:

private void lstPracs_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.lstPracs.SelectedValue.GetType() == typeof (Int16))
{
AttDetailsFrm frmAttDetails = (AttDetailsFrm)
FormMgr.Instance.OpenForm (Type.GetType
"CompTrackerPPC.AttDetailsFrm"));
frmAttDetails.PracId = (Int16)this.lstPracs.SelectedValue;
frmAttDetails.Show();
this.Close();
}
}

It seems the exception is raised after the above method exits.

Any suggestions would be greatly appreciated.

Ollie
 
I can send/post code snipets but I do not see how I can send a reproducable
version of the situation without sending the entire app.

Would code snipets/ class files help?

Cheers,
Ollie

Sergey Bogdanov said:
Okey, can you show us reproducible example of the issue? Or send it
directly to me.

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

Thanks to all for your suggestions.

I tryed using
frmAttDetails.ShowDialog();

but the ObjectDisposedException was still raised. I also confirmed that the
form that is being closed is not the main form. I have yet to try the timer
solution. I am still at a loss to determine why this ObjectDisposedException
is being raised in the first place.

Anymore feedback is greatly appreciatd,
Ollie

:

The problem is that you are trying to close the main form. Once main
form was closed the application exits. To solve your problem just replace:

this.Close();

with

this.Hide();

.... or follow Darren's suggestion to use ShowDialog instead.


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com


Ollie wrote:

I am getting an ObjectDisposedException on closing a form and am at a loss as
to why it is happening. My understanding is that such an exception occurs
when an disposed object is referenced. However, I cannot identify where this
is happening. Below is the code:

private void lstPracs_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.lstPracs.SelectedValue.GetType() == typeof (Int16))
{
AttDetailsFrm frmAttDetails = (AttDetailsFrm)
FormMgr.Instance.OpenForm (Type.GetType
"CompTrackerPPC.AttDetailsFrm"));
frmAttDetails.PracId = (Int16)this.lstPracs.SelectedValue;
frmAttDetails.Show();
this.Close();
}
}

It seems the exception is raised after the above method exits.

Any suggestions would be greatly appreciated.

Ollie
 
Back
Top