开发者

Implementing auto-save in WPF / MVVM / NHibernate

开发者 https://www.devze.com 2022-12-28 14:42 出处:网络
My client likes programs like Microsoft OneNote where changes are saved automatically, and he can choose to discard when he explicitly wants to do so. I will have to implement some undo functionality,

My client likes programs like Microsoft OneNote where changes are saved automatically, and he can choose to discard when he explicitly wants to do so. I will have to implement some undo functionality, but I'll figure that out some other time.

With NHibernate, I suppose I can call ISession.Update on every single property / binding change, but I can see real pain with this approach down the road. I am not a fa开发者_如何转开发n of timers, but maybe a 5 second timer that starts on property / binding change and at timer end use BackgroundWorker thread to save to db.

What do you think?


A ISession.Update on every property-change isn't a good idea normally. The property-change-events are fired quite often. It could slow down your application when you do ISession.Update on every change. This will probably lead to a bad user experience.

In our Application has the same behavior. We store the changes when a View is closed (an some other related event). For example when the user closes a tab, the data which was displayed in that tab is closed.

An additional timer is probably a good idea to prevent data loss when the application crashes / unexpected happens.

0

精彩评论

暂无评论...
验证码 换一张
取 消