eea*_*dev 14 c# windows-store-apps background-task
我的平板电脑运行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();
Run Code Online (Sandbox Code Playgroud)
我的应用程序有锁屏访问
await BackgroundExecutionManager.RequestAccessAsync();
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我错过了什么吗?
您必须添加SystemConditionType.SessionConnected条件,每次用户登录到Windows时都会发生这种情况.
在使用此触发器类型成功注册后台任务之前,必须将应用程序置于锁定屏幕上.
编辑:
在这个网址上,您可以找到有关您需要的官方文档以及如何使用它:
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977056.aspx
| 归档时间: |
|
| 查看次数: |
1909 次 |
| 最近记录: |