c# – Windows Phone 7 Mango(7.1) – 后台任务未重复调用
发布时间:2020-12-15 17:17:48 所属栏目:百科 来源:网络整理
导读:我正在使用后台任务在应用程序未运行时执行活动.下面是我应该每30分钟调用一次的示例代码,并将时间戳添加到Isolated Storage上的文件中.问题是,后台任务(OnInvoke事件)仅在我添加它时调用(ScheduledActionService.Add(periodicTask);).它不是每30分钟调用一
我正在使用后台任务在应用程序未运行时执行活动.下面是我应该每30分钟调用一次的示例代码,并将时间戳添加到Isolated Storage上的文件中.问题是,后台任务(OnInvoke事件)仅在我添加它时调用(ScheduledActionService.Add(periodicTask);).它不是每30分钟调用一次.
protected override void OnInvoke(ScheduledTask task) { using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists("testbg.txt")) { EditExistingFile("testbg.txt",DateTime.Now.ToString() + Environment.NewLine); } else { CreateNewFile("testbg.txt",DateTime.Now.ToString() + Environment.NewLine); } } NotifyComplete(); } public static void StartBackgroundTask() { PeriodicTask periodicTask = new PeriodicTask("Project One Tasks"); // The description is required. This is the string that the user // will see in the background services Settings page on the device. periodicTask.Description = "Performs various activities related to Project One."; periodicTask.ExpirationTime = DateTime.Now.AddDays(10); // If the agent is already registered with the system,// call the StopPeriodicAgent helper method. if (ScheduledActionService.Find(periodicTask.Name) != null) { StopBackgroundTask(); } ScheduledActionService.Add(periodicTask); } 编辑: 有一点我注意到,当我启动Periodic或ResourceIntensive Task时,我得到以下对话框: 适用于Windows Phone的Microsoft Visual Studio 2010 Express 与设备的远程连接已丢失.请验证设备连接并重新启动调试. 好 有人在调用任务时收到此消息吗? 解决方法
Beta 2改变了这种行为.你有没有重新检查(并测试它芒果手机而不是模拟器)?
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |