Why I get an 'System.ObjectDisposedException' when open the second time a Form?

DevilAkuma

Active member
Joined
Oct 24, 2005
Messages
37
Programming Experience
Beginner
I created a simple form with the .NET's assistant.

At the top of the code, I have...
VB.NET:
Dim myForm As New myForm
And when I click a button I do only this...
VB.NET:
myForm.Show()
The first time runs very well, but when I close this form, and try to open it another time I get a sad 'System.ObjectDisposedException'. Is it normal?

Thanks in advance.
 
Last edited:
Yes this is normal. When you close a form it gets disposed of (eventually) and that instance is no longer existant. Therefore before calling the show method for a form you should check to see if it exists and if it has been disposed of and if it doesn't exist or has been disposed then create a new instance. I'm not following your code posted above however since you declare myForm but then use the variable cercalia. I've no idea what cercalia is. :)
About the first line of code: it's not a good idea to have the variable name the same as the class name, it's confusing.
 
Sorry... I've edited my first post. Cercalia was another part of my code... I wanted to write myForm.Show().

About your explanation, tomorrow I'm going to try it.

Thanks a lot!
 
Back
Top