Solved

ObjectDisposedException

Posted on 2008-11-01
6
814 Views
Last Modified: 2013-11-17
Hi,

I use some custom controls on my CF2 Form I add dynamic and need to remove dynamic from my Form.
The matter is that I get an ObjectDisposedException when I dispose it at some of it's events.

So in the constructor I apply some events to the parent form eg.:
this.Parent.MouseUp += new MouseEventHandler(Parent_MouseUp);

When I dispose it I remove these events:
protected override void Dispose(bool disposing)
{
   this.Parent.MouseUp -= Parent_MouseUp;
}

However this don't solve the problem.
What works for me is to catch the ObjectDisposedException but I think this is not the cleanest way to make it working ...

Maybe somebody know a better solution?

Thanks,

Andre
0
Comment
Question by:andre72
  • 3
  • 3
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
you don't need that. Dispose() function is intended to free non-managed resources like GDI or database resources.
The events will be removed without your intervention when the object is no longer used.
0
 

Author Comment

by:andre72
Comment Utility
Thanks for the information so you've also any idea about the Exception?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
the exception is produced because the parent window was disposed at the moment the line of code is excecuted. But as I said, what you are doing is not needed.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:andre72
Comment Utility
Sorry for missunderstanding - it doesn't matter if I include it or not. Because of your hint I removed the lines as the dispose do it itself ...
But the problem is still the same ...
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
Comment Utility
remove all the dispose method.
0
 

Author Comment

by:andre72
Comment Utility
The control get it's events from the parent control:
                this.Parent.MouseDown += new MouseEventHandler(Parent_MouseDown);
                this.Parent.MouseUp += new MouseEventHandler(Parent_MouseUp);
                this.Parent.MouseMove += new MouseEventHandler(Parent_MouseMove);

Isn't there a way to clear any event of it and / or clear the message queue?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now