Question

I'm working on a C# project where you load images and do stuff with them.

There's a button that closes the current project the user is working on.

Is there a way to dispose all elements at once without doing Application.Restart();?

Should I go element by element and disposing/setting to null etc?

Thanks!

Was it helpful?

Solution

There are basically two types of resources you need to think of

1.) "managed" stuff like basic variables, UI elements etc. These are disposed as expected when you close the form and you don't have to pay attention to them.

2.) resources that need to be disposed, like certain database access objects, stream readers, timers, etc etc. If you do operations like this, make sure you dispose them before closing the form, or else it may and most of the time will continue working in the background and your app won't close properly. Learn how to properly dispose objects in C#, for instance

http://www.codeproject.com/Articles/15360/Implementing-IDisposable-and-the-Dispose-Pattern-P http://lostechies.com/chrispatterson/2012/11/29/idisposable-done-right/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top