Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 823
  • Last Modified:

ObjectDisposedException

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
andre72
Asked:
andre72
  • 3
  • 3
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
andre72Author Commented:
Thanks for the information so you've also any idea about the Exception?
0
 
Jaime OlivaresSoftware ArchitectCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
andre72Author Commented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
remove all the dispose method.
0
 
andre72Author Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now