all groups > dotnet compact framework > december 2007 >
You're in the

dotnet compact framework

group:

ObjectDisposedException


ObjectDisposedException Hilton
12/29/2007 3:21:54 AM
dotnet compact framework:
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

RE: ObjectDisposedException Simon Hart [MVP]
1/2/2008 6:59:08 AM
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 Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


[quoted text, click to view]
Re: ObjectDisposedException Hilton
1/5/2008 12:07:43 AM
[quoted text, click to view]

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

AddThis Social Bookmark Button