应用程序的第一次执行
答
你可以把代码中,在应用程序的生活方式
下方,显示一个Windows手机应用程序的应用程序生命周期,并显示出现在App.xaml.cs文件中的4个事件的链接所描述的各种事件
答
或在更短的线 可以在
私人无效Application_Launching做验证(对象发件人,LaunchingEventArgs E) { }
保存一个变量在所述分离的储存空间。 尝试获取它,如果你不能这意味着它是第一次使用应用程序,但如果你能够加载变量,那么应用程序已经开始。
希望它能帮助
答
我也建议你使用IsolatedStorage,而是专门增加一个布尔钥匙独立存储,并验证它是否设置为true。
例子:
using System;
using System.IO.IsolatedStorage;
/// <summary>
/// Application Settings
/// </summary>
public class AppSettings
{
/// <summary>
/// IsFirstStart IsolatedStorage Key.
/// </summary>
public const string IsFirstStartKey = "firststart";
/// <summary>
/// Gets or sets a value indicating whether this instance is the first start.
/// </summary>
/// <value>
/// <c>true</c> if this instance is the first start; otherwise, <c>false</c>.
/// </value>
public static bool IsFirstStart
{
get
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(AppSettings.IsFirstStartKey))
return (bool)IsolatedStorageSettings.ApplicationSettings[AppSettings.IsFirstStartKey];
else
return true;
}
set
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(AppSettings.IsFirstStartKey))
IsolatedStorageSettings.ApplicationSettings[AppSettings.IsFirstStartKey] = value;
else
IsolatedStorageSettings.ApplicationSettings.Add(AppSettings.IsFirstStartKey, value);
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
}
用法:
if (AppSettings.IsFirstStart == false)
{
// First Start, do some logic
// ...
// But remember to set it to true, once it's done!
AppSettings.IsFirstStart = true;
}
首次启动后安装?不,你不需要做任何事情,如果这对于应用程序逻辑没有必要的话 – Ku6opr 2012-03-02 15:20:39
这个评论甚至意味着什么? – MoonKnight 2012-03-02 15:24:14
对不起,我读了第一句话作为一个问题...对不起一次 – Ku6opr 2012-03-02 15:31:14