This project is read-only.

Saving state realtime

May 31, 2013 at 11:26 PM
Markus,

As I understand it, Win 8 apps need to save state so that they can resume if the OS shuts them down. I like this.

Does Code FW support this? If so, what do I need to do to implement it?

If not, are there any plans to support it at some point down the road?

Thanks,

Fletcher
Jun 2, 2013 at 9:40 PM
"Tombstoning", yes. It's a WinRT thing, really. We are not doing anything with that in .NET. I suppose .NET apps could also use APIs to get notification when the OS shuts down and then save your state any way appropriate. I am not sure how much the framework could help with that. I guess if the view models were all serializable then we could save them away and then restart the app and navigate to all the same UIs and load that state again.

It's an intriguing though. Maybe I'll take some notes on this. I am not sure how high priority this is though, because when Windows goes into sleep mode or hibernation, it already saves the state of all desktop apps and starts them right back up to that. (In WinRT things a different, and state needs to be preserved manually). So I am not really sure we have this problem, do we?


Markus
Jun 11, 2013 at 6:13 PM
Markus,

In the case of a user, if they shut down, go to lunch and leave their application running (but the computer is locked and so someone shuts it down), the system crashes (I know Windows computers don't crash, but hey, life happens), a bug in the code (not my code of course....), a power failure, etc. - I would like to be able to save the state - at least of the edited data. Some of my users are not the fastest at data entry and often have to write up detailed notes about certain things - and it's very frustrating if there is any kind of an issue and they lose that work.

The easiest way I can figure is to have an option which, if set, ties an event to the view model that auto saves all the values of the properties to a temporary cache - which is then deleted once the user saves or cancels the changes.

If I find a cache file on startup, I can ask the user if they want to continue editing that data or to discard it.

I'll figure it out.

Thanks,

Fletcher
Jun 14, 2013 at 1:15 PM
I actually have some customers who do that sort of thing. They basically save "recovery information" which is only deleted when the record is saved for real. If the recovery information is there when the app launches, they know it must have crashed and restore from that.

Technically speaking, what you need is a serialization mechanism. ViewModels as such are not necessarily directly serializable, because they could have all kinds of stuff in them. However, every view model that is savable must achieve that task in some way. Typically this happens by calling a service. So the developer creates some way of mapping the view model into service contracts and then sends those off to the service. Service contracts ARE serializable by definition. So this is where a recovery-file mechanism could come in. Run a timer or something that does the serialization to contract every few minutes and then grab that contract as XML or so, and save that away to a file.


Markus