I am trying to hide my main form on a certain event and then show it again later. The problem is that the form gets disposed when I hide it.
My code for hiding the form:
private void MessageRecived(object sender)
{
//Do stuff
if (status == NetConnectionStatus.Connected)
{
this.Hide();
}
else if (status == NetConnectionStatus.Disconnected)
{
this.Show();
}
//Do some more stuff
}
When the "this.Show()" method is called, the following exception is thrown:
System.ObjectDisposedException
Additional information: Cannot access a disposed object.
I have also tried to use "this.Visible = false" and "this.SetVisibleCore(false)" but I get the same result.
How can I hide the form without it getting disposed?
EDIT:
I found my mistake: There was an object in my code that referenced the form, and it closed it. Thanks to Justin Harvey who pointed out that something else is using the form.