ObjectDisposedException... but no object???

  • Thread starter Thread starter joelcochran
  • Start date Start date
J

joelcochran

I'm running VS2005 and it seems that whenever I try to exit a form I
receive the following:

ObjectDisposedException was unhandled.
Safe Handle was closed.

The Stacktrace shows this:
at System.Runtime.InteropServices.SafeHandle.DangerousRelease()
at System.Threading.RegisteredWaitHandleSafe.Finalize()

I don't even know where to begin since the exception does not indicate
a particular object.

Any help would be most appreciated.
 
Is that the full stack trace?

It looks like a registered wait handle already has a reference count of zero
when it is finalised, which should never occur for safe handles that have
not been explicitly disposed. Are you making any calls to
SafeHandle.DangerousRelease() that might be unbalancing the reference
counting on the safe handle? If you're not aware that you're using safe
handles, are you using any custom controls or using the thread pool?
 
I am definitely not explicitly calling SafeHandle.DangerousRelease().
I do have user controls and some threading.
 
I might have misunderstood your original post, so could you clarify if you
are seeing this when

a) closing a form at run-time
b) closing the form designer at design-time in VS 2005.

If it's a), you'll have to provide some more information about how you're
using threading. E.g. one of the ways to create an instance of
RegisteredWaitHandleSafe (an internal class) is to call
ThreadPool.RegisterWaitForSingleObject, but without more details it's
difficult to offer any concrete advice.

If it's b), have you tried debugging VS 2005 with another instance of VS
2005? You also might want to turn on all MDAs when debugging.
 
I receive the error when I close a form at run time (executed in VS
using F5). I have seen this behaviour both in forms that use threading
and forms that do not.

Interesting thought about debugging VS with VS... no idea how I would
go about such a thing. And what are "MDAs"?

Thanks for your patience,

Joel
 
I don't think debuggin VS will help you, it's only useful for when you're
debugging design-time issues. MDAs are Managed Debug Assistants, and you can
turn them on/off via the exceptions dialog (under the Debug menu). It's
usually worthwhile turning them all on initially, although some scenarios,
such as XML serialization, can cause them to fire frequently, but you can
always turn them off again.

Is this a modal or a non-modal form that you are displaying? Is it being
disposed of after it is being closed? Can you post some code?
 
Back
Top