C#/WPF: Implementing Autosave
how could i implement autosave in C#? i felt that saving to the currently open file is a simple but i may not want to overwrite my previous file (or should i just do that? i think google docs saves/overwrite the document tho they have version control?). i thought of saving to ano开发者_如何转开发ther file, but where do i save to?
also i guess i will have to know if there's any autosave files to retrieve and after a explicit save, i should remove the autosave file associated with the current document
Current versions of Microsoft Office (for example) save to a "shadow copy" of the working file. Depending on how you want it to work, you can have writes applied to the shadow copy every n seconds or when certain types of actions are taken.
When the program is shut down, the original is deleted and the shadow copy is renamed to the original. There are lots of options and strategies within this technique that can be applied depending on your particular situation and requirements.
You should create a Temporary File for the autosave. If the User saves, you can delete the file, and if your app crashes and is restarted it can load the last autosaved state from the file.
精彩评论