Cannot access a disposed object named "Panel".

  • Thread starter yevgeny.pechenezhsky
  • Start date
Y

yevgeny.pechenezhsky

I am receiving the following error while running my application:

------------------------------------------------------------------------------------------------
An unhandled exception of type 'System.ObjectDisposedException'
occurred in system.windows.forms.dll

Additional information: Cannot access a disposed object named "Panel".
------------------------------------------------------------------------------------------------

I am using Visual Studio .Net 2003 on the 1.1 Framework. Following is
the relevant C# source code which causes this error:

------------------------------------------------------------------------------------------------
private Form displayedScreen = null;

public void displayScreen(Form form, bool allowReload)
{
if (this.displayedScreen != null)
{
// do not replace the displayed form with the same type
if (allowReload && (this.displayedScreen.GetType() ==
form.GetType()))
return;

// destroy the old form through its stored reference
this.displayedScreen.Dispose();
}

// set the new form's properties and display it
form.TopLevel = false;
form.Parent = this.pnlContent;
form.Show();

// store a reference to the new form to be displayed
this.displayedScreen = form;
}
 
V

VJ

does not look correct...do you assign somewhere form with displayedscreen.
That could do the below error.
 
Y

yevgeny.pechenezhsky

I do not assign the form anywhere except inside the method (store it in
displayedScreen). When I call the method, I pass in an anonymous object
like this: displayScreen(new LoginForm, false);
 
C

connected

To anyone else who has problems with Dispose() glitches, the reason
this happens is a bug in the original .NET 1.1 Framework. Upgrading to
..NET 1.1 SP1 fixes this. Good day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top