Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metro (XAML/C#): detect installation and/or first run

When creating Metro applications in XAML/C#, how do I detect when the application is first installed or run for the first time since installation (or potentially upgrade)? I need to use this opportunity to ensure that my database schema is correct and potentially synchronise some base data.

I had hoped that I could pick this up from the LaunchActivatedEventArgs within the OnLaunched method, but there does not seem to be a valid value for the Kind or PreviousExecutionState that I can use.

Thanks.

like image 745
Martin Robins Avatar asked Jun 03 '12 16:06

Martin Robins


1 Answers

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localsettings.aspx#Y0

When your app starts, write a setting called "AppHasBeenStarted" or something to LocalSettings. If the setting has not already been written, you know your app hasn't been started before. And you could improve on this, by making it "AppVersion", and writing the app's version. This way your app can detect upgrades by comparing the stored version with its own version.

like image 108
fabspro Avatar answered Sep 22 '22 10:09

fabspro