Solved

ObjectDisposedException

Posted on 2008-11-01
6
815 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
ID: 22857473
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
ID: 22857484
Thanks for the information so you've also any idea about the Exception?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22857647
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:andre72
ID: 22857681
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
ID: 22859907
remove all the dispose method.
0
 

Author Comment

by:andre72
ID: 22862266
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# guarantee sql connection close 6 39
Graphics 2 27
VB.NET 2008 (3.5 Framework) Remove all items from List 3 21
Add different cell to otherwise similiar row 4 38
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

786 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