HighTechTalks DotNet Forums  

ObjectDisposedException

Dotnet Framework (Compact Framework) microsoft.public.dotnet.framework.compactframework


Discuss ObjectDisposedException in the Dotnet Framework (Compact Framework) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Hilton
 
Posts: n/a

Default ObjectDisposedException - 12-29-2007 , 06:21 AM






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



Reply With Quote
  #2  
Old   
Simon Hart [MVP]
 
Posts: n/a

Default RE: ObjectDisposedException - 01-02-2008 , 09:59 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


"Hilton" wrote:

Quote:
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




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.