Search code examples
uwpbackground-task

UWP TimeTrigger won't fire


I am trying to run a background task every 15 minutes using the TimeTrigger but for some reason it wouldn't fire. Tried the Lifecycle Events method and it worked. Checked the task is registered in the power shell. What else can be wrong? One thing I found strangely is when I run

var allowed = await BackgroundExecutionManager.RequestAccessAsync();

I get back BackgroundAccessStatus.AllowedSubjectToSystemPolicy instead of

BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity or BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity

Is that the problem? What is BackgroundAccessStatus.AllowedSubjectToSystemPolicy?

Update:

AllowedMayUseActiveRealTimeConnectivity and AllowedWithAlwaysOnRealTimeConnectivity are deprecated.

Reboot made it work, both the desktop and mobile. Apparently it's easy to crash the background task process.

Also use this to debug on the desktop:

https://learn.microsoft.com/en-us/windows/uwp/launch-resume/debug-a-background-task


Solution

  • Hi if you get Allowed so it should works fine but double check some points I mention below : 1-Make sure your background Task project be a Windows Runtime Component Project not a class library or others .

    2-Make sure your background task project now is a reference in the project you want to call it .

    3-Make sure you define your background task , it's entry point and it's type in AppxManifest

    4-If all of the things I mentioned were OK so in your C# code call your Background task entry point in this way , some times it will solve your problem .

    BackgroundTaskBuilder build = new BackgroundTaskBuilder();
    build.TaskEntryPoint = typeof(BGTaskRTComponentProj.BGTaskClass).FullName;