Monday, 12 August 2013

C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please

C# crashing with Form.show() command, ObjectDisposedException - Deeper
look / explanation please

I'm working on a project, and have two forms - One is the main form, the
other a console-akin form made up of a split panel and a listbox (in panel
1)
I call a method ( writeToConsole(string textToWrite) ) which - as the name
suggests - adds a line of text to the list box in the consoleWindow form
The issue I'm having is that, to show this form, I use a button that calls
the show command. However, if I close said form with the "x" button in the
top right corner, and then click the Show Console Button again, I get
this:
ObjectDisposedException
"Cannot access a disposed object.
Object name: 'consoleOutput'."
Now, I sort of understand the issue - I had it a month or two ago, and
from what I understand its because when you press the x it closes the
form, meaning it has to be reinitialized / reloaded before it can be show
- hence the error is ( in a very basic nutshell) "I can't show you
something that doesn't exist / is in limbo"
(Again, thats the whole "Sort of on the face of it thats what it means,
but really no its deeper than that" view - I understand its deeper than
just that)
My question is this: Can someone please explain to me what exactly is
going on / wrong, and the best way to do this sort of thing?
I understand the concept of the error, and I know a way or two to fix it,
but I'm wanting to be a programmer, hence would like to know (at the very
least) the flow of events for this situation and expand on my knowledge
Thanks

No comments:

Post a Comment