ObjectDisposedException

  • Thread starter Thread starter P
  • Start date Start date
P

P

I have something that drives me crazy. Sometimes when I shut down my
application I recieve an ObjectDisposedException but other times I dont get
it.
I have seen a lot of articles on this and Im just curious as to some common
reason why this might occur. I use ShowDialog only in my application and
after each
such call I have an Dispose() of it. However this Exception can occur even
if I just start my application and then close it without doing anything
else.

Suggestions?

<P>
 
If you can reproduce the problem, while running under debugger, try to
notice, which method is throwing the exception. Look at the Stack window, to
see the actual location, right-click and check "Show non-user code"
 
Do you create an asynchronous thread with a callback ( socket for example )?

Ruediger
 
I had the same problem and finally tracked it down to an
Application.DoEvents() call that I had in a loop. The app responded to the
Application.DoEvents() and was exiting the program but the loop was still
running and was referencing objects (controls) that had already been
disposed. I added try/catch/finally code and caught the
ObjectDisposedException then called Application.Exit. This fixed the problem
and the memory was released and the programmed behaved as desired.

HTH
 
Yes. While starting up I make an asynchronous call to a web service.
Basically because it seems the first call takes a longer time than
the following so thought I spare the user that extra annoyance. If this is
indeed the problem then how can I work around this.

<Regards>

P
 
In case of my little socket app. i'm using a try/catch construct which
simply ignores this special error:
catch (Exception e)

{

if (e.GetType().FullName != "System.ObjectDisposedException")

ShowTheErrorMessage.....

}

Regards

Ruediger
 
Back
Top