当前位置: 首页 > 编程语言 > C#

WP7中是否有“首次运行”标志分享

时间:2023-04-11 03:42:15 C#

WP7中是否有“首次运行”标志想知道WP7中是否有“首次运行”标志或类似的标志。我的应用程序从独立存储中获取一些东西,所以我想在第一时间确定是否有必要。我目前正在使用if来检查命名的存储对象是否存在,但这意味着我无法按照我想要的方式处理任何内存丢失错误。我认为这没有内置功能......但我知道你的意思:-)我在开源可汗学院中使用iso存储为WindowsPhone应用程序实现了“首次运行”。我所做的就是在iso存储中查找一个非常小的文件(我只写一个字节)...如果它不存在那么它是第一次,如果它存在那么应用程序已经运行了不止一次。如果需要,请随意查看源代码并采用我的实现:-)privatestaticboolhasSeenIntro;///只有在用户第一次运行时才会返回false。///此后每次,占位符文件都将写入磁盘///并将触发true值。publicstaticboolHasUserSeenIntro(){如果(hasSeenIntro)返回真;using(varstore=IsolatedStorageFile.GetUserStoreForApplication()){if(!store.FileExists(LandingBitFileName)){//只需写一个一个字节长的占位符文件,这样我们就知道它们在使用之前已经登陆(varstream=store.OpenFile(LandingBitFileName,FileMode.Create)){stream.Write(newbyte[]{1},0,1);}返回假;}hasSeenIntro=true;返回真;正如@HenryC在对已接受答案的评论中所建议的那样,我使用IsolatedStorageSettings来实现“首次运行行为”,这是代码:privatestaticstringFIRST_RUN_FLAG="FIRST_RUN_FLAG";私人静态IsolatedStorageSettings设置=IsolatedStorageSettings.ApplicationSettings;publicboolIsFirstRun(){如果(!settings.Contains(FIRST_RUN_FLAG)){settings.Add(FIRST_RUN_FLAG,false);返回真;}else{返回错误;如果版本发生变化,有时我们需要对Windows商店的每次更新做一些事情把这段代码放在App.xaml.cs上面是C#学习教程:WP7有没有“首次运行”标志?分享所有内容,如果对大家有用,需要了解更多C#学习教程,希望大家多多指教关注—privatestaticstringFIRST_RUN_FLAG="FIRST_RUN_FLAG";私人静态IsolatedStorageSettings设置=IsolatedStorageSettings.ApplicationSettings;私有静态字符串_CurrentVersion;publicstaticstringCurrentVersion{get{if(_CurrentVersion==null){varversionAttribute=Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute),true).FirstOrDefault()作为AssemblyFileVersionAttribute;if(versionAttribute!=null){_CurrentVersion=versionAttribute.Version;}否则_CurrentVersion="";}返回_CurrentVersion;{如果(!settings.Contains(FIRST_RUN_FLAG)){settings.Add(FIRST_RUN_FLAG,CurrentVersion);动作(当前版本);}elseif(((string)settings[FI??RST_RUN_FLAG])!=CurrentVersion)//它退出但是版本不匹配{settings[FI??RST_RUN_FLAG]=当前版本;动作(当前版本);}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: