If you want to load your count
every time the App is Launched then put your code in Application_Launching
event in App.xaml.cs:
// declare static variable which you will be able to access from anywhere
public static int count;
private void Application_Launching(object sender, LaunchingEventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("count")) count = (int)settings["count"];
else count = 0;
}
On Clising event - save your variable:
private void Application_Closing(object sender, ClosingEventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("count")) settings["count"] = count;
else settings.Add("count", count);
settings.Save();
}
From anywhere in your code, you should be able to access your variable like this:
int myVariable = App.count;
App.count++;
// and so on
Note that you may also think about Activated
and Deactivated
events - for more information read MSDN.
I also don't know what flag
suppose to do, but code above should save your variable just fine.