How often you save depends on your application. However, the key timings are:
- Launch
- Activated
- MMG
- Closing
Launching is called when the application is first launched from the main screen, and Closing is called when the user clicks the back button to exit your application. Naturally, you most likely want to keep persistent data in the Closing event.
Activated is called when the user has closed your application using the Windows button and returned to it by clicking the "Back" button. This is not called if the user launches the application for the first time.
Similarly, the Deactivated event is Deactivated when the user clicks the Windows button. Depending on your application, you want to save the transient data at this point, so that when recovering, you can present the illusion that your application was not closed at all. (Otherwise, for example, all text fields will become empty, even if the user enters data before pressing the Windows button).
These are major events, so you can create your own application around this. It should be remembered that if your save files are large and take longer than 10 seconds to save after the Closing event is Closing , your application will be terminated immediately, which will damage the save file. Therefore, for large save files, you should plan ahead, saving incrementally (for example, after the user has made changes that must remain constant).
There is no one size fits all solution, since preserving timings is highly dependent on the type of application being developed. Read the MSDN page of the runtime model , as it is discussed in more detail and contains code examples.
source share