ObjectDisposedException

  • Thread starter Thread starter Hilton
  • Start date Start date
H

Hilton

Hi,

I am seeing these ObjectDisposedExceptions very infrequently, but I am
seeing them. They are being thrown on a button/control which are part of a
form; e.g. this.button.ForeColor = Color.Black throws (very infrequently).
I definitely do not dispose of the form or these buttons before the
exception is thrown. I add the button like: "this.button.Parent = this".
Obviously I am still holding a reference to the control, and I definitely do
not dispose of the control or the form (I dispose of the form when exiting
the app and definitely have not got there yet).

The latest exception occured when a user tapped on a button and the app went
to change the colors of other buttons on the page by setting their ForeColor
and BackColor - seems innocent enough.

As a developer, when unexplained things happen, you start questioning even
the smallest thing, so today's question is: Is "this.button.Parent = this"
*exactly* the same as "this.Controls.Add (this.button)". I use the former
because it is faster. See
http://msdn2.microsoft.com/en-us/library/aa446535.aspx

I do call SendToBack and BringToFront on the form when required, but that's
just a Z-order thing and should not dispose of controls/buttons.

Any ideas or known bugs in the CF to make this happen? Very curious...

Hilton
 
Setting Parent of a control is the same as adding your control to the
Control.ControlCollection. I am guesing, but maybe Windows is trying to
shutdown your app due to memory contraits reached as when this occurs the
form sometimes does not disappear immediately. Have you tried setting a hook
onto the UnhandledException of the AppDomain class, then inspecting the
memory?
 
Simon said:
Setting Parent of a control is the same as adding your control to the
Control.ControlCollection. I am guesing, but maybe Windows is trying to
shutdown your app due to memory contraits reached as when this occurs the
form sometimes does not disappear immediately. Have you tried setting a
hook
onto the UnhandledException of the AppDomain class, then inspecting the
memory?

Simon, thanks for the reply. I'm trying a few things, I'm also seeing a
strange stack overflow exception on a user's device. I cannot reproduce
either of these exceptions. I'm starting to really question the obfuscator.
I'll start a new thread about obfuscators.

Hilton
 
Back
Top