Perform update on app start-up

270 views
Skip to first unread message

Atanas Valev

unread,
Feb 22, 2016, 6:01:21 AM2/22/16
to NAppUpdate
Hi,

I have an app that starts-up with Windows and (unless explicitly closed by the user) runs until shutdown in the tray. I want to be able to check for and prepare updates while the app is running, but only apply them when the user restarts his computer (I will have mostly cold updates).
I am well aware of the scenario where I run ApplyUpdates when the user exits the app, but that doesn't really work in my case, because that will be most often when he shuts down Windows, and that doesn't allow apps to open new tasks (the auto-updater in this case), so I think the best solution for me is to do it on app start (check for already prepared updates and call ApplyUpdates before doing anything else).
Now my question is: How do I go about doing that? Persisting the state of the UpdateManager on disk sounds like exactly what I want -- to have it in the UpdatesPrepared state at startup with everything ready, but that's veery hacky and I'm not even sure it'll work. Or am I going about this entirely wrong?

Thanks!

Atanas Valev

unread,
Mar 8, 2016, 4:06:24 AM3/8/16
to NAppUpdate
Hi,

I ended up using BinaryFormatter to serialize the update Tasks after updates are prepared. On the next start of the app, I first check for previously serialized updates and if there are any I use a dummy update source and feed reader. The update source just returns empty strings and the feed reader returns a single custom dummy task. Using this I call synchronously CheckForUpdates and PrepareUpdates to get UpdateManager in the correct state to call ApplyUpdates. Since no networking is going on, that's okay and since there is a Task, the PrepareUpdates call doesn't complain there are no updates. Afterwords I cast Tasks to List (I know it is a list and hope it won't change in the future) and add all my now deserialized tasks back to it and call ApplyUpdates. It all happens quickly enough to be unnoticeable. Since the Update Tasks are already serializable, this works like a charm and it's the least hacky solution I could come up with (without modifying the library). 

I believe others might like to do the same thing, so I would be happy work on a way to do this without these hacks, I just need a hand to decide what's the best way to do it.
Reply all
Reply to author
Forward
0 new messages