我正在使用后台任务在应用程序未运行时执行活动.下面是我应该每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改变了这种行为.你有没有重新检查(并测试它芒果手机而不是模拟器)?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。