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


i'm working on project, , have 2 forms - 1 main form, other console-akin form made of split panel , listbox (in panel 1)

i call method ( writetoconsole(string texttowrite) ) - name suggests - adds line of text list box in consolewindow form

the issue i'm having that, show form, use button calls show command. however, if close said form "x" button in top right corner, , click show console button again, this:

objectdisposedexception   "cannot access disposed object. object name: 'consoleoutput'." 

now, sort of understand issue - had month or 2 ago, , understand because when press x closes form, meaning has reinitialized / reloaded before can show - hence error ( in basic nutshell) "i can't show doesn't exist / in limbo"

(again, thats whole "sort of on face of thats means, no deeper that" view - understand deeper that)

my question this: can please explain me going on / wrong, , best way sort of thing?

i understand concept of error, , know way or 2 fix it, i'm wanting programmer, hence know (at least) flow of events situation , expand on knowledge

thanks

just safe:

consoleoutput consoleoutput = new consoleoutput();          private void btnshowconsole_click(object sender, eventargs e)         {             //check see if console visible, of if not, make             //if on other hand, bring front show user             if (consoleoutput.visible == false)                 consoleoutput.show();             else                 consoleoutput.bringtofront();         } 

native operating system resources valuable commodity. in order use them efficiently, programs should not hold onto resources longer necessary. in managed code, .net framework provides system.idisposable interface. implementations of interface can instructed, via dispose() method, release or dispose resources that implementation responsible creating (managed or unmanaged) in timely fashion.

in case of winforms application, visual components involve native operating system resources degree, , components implement idisposable. when dispose()d, or close()d, release native resources (although component still accessible program via reference).

one of requirements of idisposable contract implementations should not allow access object via public member if it's been disposed. if such access attempted, objectdisposedexception should thrown.

in specific case, have couple of options:

1) arrange form doesn't close, instead gets hidden, , can made visible again if main form needs show again (note if form doing kind of work, hiding won't stop work, , may or may not desired in case).

2) create new instance of form every time want show (but being displayed on previous incarnation of form lost when it's closed).


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -