如何在启动时启动后台任务 – Windowsapp store应用
我的平板电脑运行Windows 8.1专业版。
它有一个后台任务,每15’由一个时间触发器触发。 它工作得很公平。
问题是我需要在设备的每次启动(启动应用程序)时自动启动后台任务。
我用这段代码注册了我的bg:
builder.Name = "bikePositionUpdate"; builder.TaskEntryPoint = "BackgroundTaskGps.BikeGPSPositionUpdateBackgroundTask"; builder.SetTrigger(new TimeTrigger(15, false)); // // adding condition SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable); SystemCondition userPresentCondition = new SystemCondition(SystemConditionType.UserPresent); builder.AddCondition(internetCondition); builder.AddCondition(userPresentCondition); BackgroundTaskRegistration taskRegistration = builder.Register();
我的应用程序有锁屏访问
await BackgroundExecutionManager.RequestAccessAsync();
我怎样才能做到这一点? 我错过了什么吗?
您必须添加SystemConditionType.SessionConnected
条件,每次用户登录到Windows时都会发生这种情况。
必须先将应用程序放在锁定屏幕上,然后才能使用此触发器类型成功注册后台任务。
编辑:
在这个url上,您可以找到有关您需要的官方文档以及如何使用它:
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977056.aspx
I think you should add SystemConditionType.SessionConnected condition,where this condition will check every time theuser log on to Windows
您是否尝试将其添加到注册表中的启动时运行?
我没有8.1来检查,但如果没有从win7更改路径应该是HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Run(或HKEY_LOCAL_MACHINE)只是创建一个新的字符串值与您的应用程序的路径,它将在Windows运行时运行启动
结果await BackgroundExecutionManager.RequestAccessAsync();
应该像AllowedWithAlwaysOnRealTimeConnectivity。
这意味着:用户在对话框中选择“允许”。 该应用程序被添加到锁定屏幕, 可以设置后台任务 。
而这个BackgroundTaskRegistration taskRegistration = builder.Register();
在await BackgroundExecutionManager.RequestAccessAsync();
之后,你sholud调用await BackgroundExecutionManager.RequestAccessAsync();
您是否尝试将应用程序添加到Windows任务计划程序作为安装过程的一部分?