如何在启动时启动后台任务-Windows应用商店应用我的平板电脑运行的是Windows8.1Pro。它有一个后台任务,每15分钟由一个时间触发器触发。它工作正常。问题是我需要后台任务在设备每次启动时自动启动(启动应用程序)。我用这个代码注册了我的bg:builder.Name="bikePositionUpdate";builder.TaskEntryPoint="BackgroundTaskGps.BikeGPPositionUpdateBackgroundTask";builder.SetTrigger(newTimeTrigger(15,false));////添加条件SystemConditioninternetCondition=newSystemCondition(SystemConditionType.InternetAvailable);SystemConditionuserPresentCondition=newSystemCondition(SystemConditionType.UserPresent);builder.AddCondition(互联网条件);builder.AddCondition(userPresentCondition);BackgroundTaskRegistrationtaskRegistration=builder.Register();访问awaitBackgroundExecutionManager.RequestAccessAsync();我怎样才能做到这一点?我错过了什么吗?您必须添加SystemConditionType.SessionConnected条件,每次用户登录Windows时都会发生这种情况。该应用程序必须先置于锁定屏幕上,然后才能成功注册具有此触发器类型的后台任务。编辑:在这个网址上,您可以找到关于您需要什么以及如何使用它的官方文档:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977056.aspxhttps://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.applicationmodel.background.systemtriggertype.aspx我认为您应该添加SystemConditionType.SessionConnected条件,每次用户登录Windows时都会检查此条件您尝试在注册表中将其添加为在启动时运行?我没有要检查的8.1,但如果不更改win7的路径,它应该是HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun(或HKEY_LOCAL_MACHINE)只需创建一个包含应用程序路径的新字符串值,它将在Windowsrunstart上运行结果等待BackgroundExecutionManager.RequestAccessAsync();应该类似于AllowedWithAlwaysOnRealTimeConnectivity。这意味着:用户在对话框中选择“允许”。应用添加到锁屏,可以设置后台任务。而这个BackgroundTaskRegistrationtaskRegistration=builder.Register();在等待BackgroundExecutionManager.RequestAccessAsync();之后你应该调用awaitBackgroundExecutionManager.RequestAccessAsync();作为安装过程的一部分,您是否尝试过将应用程序添加到Windows任务计划程序?以上就是C#学习教程:启动时如何启动后台任务-Windows应用商店应用分享的所有内容。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
