We help IT Professionals succeed at work.

Clean up resources

AlexFM
AlexFM asked
on
Medium Priority
299 Views
Last Modified: 2010-04-16
I have C# Windows Forms application which works with C++/CLI Library. Library class works with camera and has clean-up function ShutDown. Wnen C# client exits, it calls ShutDown function and all works OK:

Camera camera;          // form class member

Form_Load:
    camera = new Camera();

Form_Closing:
    camera.ShutDown();

But when program has unhandled exception, camera.ShutDown function is not called. Result of this is that process remains active and must be killed from Task Manager. How can I call this function in any case?
Comment
Watch Question

Author

Commented:
Camera class has destructor which calls ShutDown, but this destructor is not called in the case of exception.

Commented:
I think you have to handle yourexceptions with try catch finally block.  In the case of unhandled exception i don't think anything gets called

Author

Commented:
I don't want to handle all exceptions, I handle only exceptions which I expect to happen. Bugs in the program must remain unhandled. My problem is that class instance is not destroyed after unhandled exception.
Commented:
Have a read at this it may help

http://blogs.msdn.com/jmstall/archive/2004/10/04/237741.aspx

Does the app actually crash when you have an unhandled exception? or does it continue

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
It looks exactly like my case. The bad news are that there is nothing to do with this.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.