Link to home
Start Free TrialLog in
Avatar of AlexFM
AlexFM

asked on

Clean up resources

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?
Avatar of AlexFM
AlexFM

ASKER

Camera class has destructor which calls ShutDown, but this destructor is not called in the case of exception.
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
Avatar of AlexFM

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of gbzhhu
gbzhhu
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlexFM

ASKER

It looks exactly like my case. The bad news are that there is nothing to do with this.