I am creating a WPF/C# app that deletes files and creates new ones before closing (from online data). The problem comes when the app randomly crashes before the new file creation process is complete or even starts.
Is there a way of file recovery (to be done within the app not just undelete apps etc) that I can use in my code so when the app crashes the file that was deleted cannot be lost?
To be more accurate I delete the 4 files at the start of the app and create new ones at the end of the app. But if the app crashes in the middle the files are lost.
How can I prevent this issue?
I tried to reduce the probability of random crashing but once in a while it still happens.
If you’re warry about lost of the file(s), you can:
A.txt(say) on startup create it’s copyA.tmpand after delete.tmpfile(s) present in directory.In this way, if something went wrong during program run, when program starts again, it will find
tmplast created, so can reconstruct information (if need) from them and continue program cycle.