I have an UWP app with a simple background task wich I want to be executed when the user starts session in Windows 10 (Anniversary Update).
I registered the task and can see it in powershell using "Get-AppBackgroundTask". The problem is the task is not executing when user starts session. Here is task registration code:
var status = await BackgroundExecutionManager.RequestAccessAsync();
bool accessgranted = status != BackgroundAccessStatus.DeniedByUser
&& status != BackgroundAccessStatus.DeniedBySystemPolicy
&& status != BackgroundAccessStatus.Unspecified;
if (accessgranted)
{
await RegisterTask("MyBgTask",
typeof(BgStartTask).FullName,
new SystemTrigger(SystemTriggerType.SessionConnected, false));
}
private async Task<IBackgroundTaskRegistration> RegisterTask(string taskName, string entryPoint, IBackgroundTrigger trigger)
{
var builder = new BackgroundTaskBuilder
{
Name = taskName,
TaskEntryPoint = entryPoint,
IsNetworkRequested = true
};
builder.SetTrigger(trigger);
var taskRegistration = builder.Register();
return taskRegistration;
}
Here is the complete check of actions made:
When I start session I can see in event viewer the following error under "BackgroundTaskInfraestructure->Operational":
Background task with entrypoint StartTask.BgStartTask and name MyBgTask can not activate; error code: 0x80131509.
I've tried to re-register the task with no success. Also, if I execute the task from VS 2017 it works ok... Any ideas please?
User contributions licensed under CC BY-SA 3.0