Click to See Complete Forum and Search --> : Deleting files when application exists


jhammer
March 15th, 2006, 05:11 PM
I create some temporary files during my application. When I try to delete the file it doesn't let me because it says the files are used. My application is the only one that can use them.
I want to catch some event that will occur just before the application ends, and put the delete there.

Is there any event that is raised just before the application exits?

stepi
March 15th, 2006, 06:37 PM
Hello,
Define ProcessExit event handler for the AppDomain.CurrentDomain. If you have a win form application define the ApplicationApplicationExit event ,which occurs when the application is just about to shut down.

hansipet
March 16th, 2006, 02:20 AM
before you delete a file you have to close it!
Regards
Hansjörg

torrud
March 16th, 2006, 06:05 AM
You could use the TempFileCollection-class. This class ensures that all temporary files inside of it will be deleted if the instance will be destroyed. I think this is what you want. But be careful, if you lost the reference to this collection inside of your application the files will be deleted likewise.