Search code examples
c#xmlautosave

Implement autosave feature of a XML


In order to give my application an autosave functionality, I'm looking at the best implementation that would optimise the 3 followings requirements:

  • safety: in order to reduce the risk of data corruption
  • user friendly: the user is not computer expert so the solution must be intuitive and friendly
  • quick to develop: I don't want to spend weeks over this implementation never

I have three solutions witch doesn't fit the 3 criteria and I'm looking for an alternative:

  • creating a simple shadow file so when the application crashes or the PC shutdown unexpectedly the application try to restore it
  • working the same way than above but storing several version of the file at different time in a temp folder
  • implement a true roll back system allowing the extend the undo/redo functionnality even the the application is restarted by keeping trace of the modification in a temp folder.

Does someone have anything to suggest?


Solution

  • For autosave, I'd simply have a background running thread that would run your Save() method silently (no popups) to a temp location (AppData system folder). You should probably keep a separate file for each session, so that you can always offer to return to a previous crashed session. On normal exit, you should delete the file to indicate the session has completed successfully.

    I'd even keep 2 files for every session an alternate saving to each, so that if a crash happens during an autosave, it won't corrupt the previous autosave.