问题
For TimerTigger() Background Task is working fine. When I want to debug I can do it from Lifecycle Events. But when I use PushNotificationTrigger() I am not able to debug the background task. I am not getting where I am doing wrong, please help. This is what I get on Lifecycle Events while debugging. This is how I am registering Background task for Raw Notifications,
if (!Windows.ApplicationModel.Background.BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name == "PushBackgroundTask"))
{
var result = await BackgroundExecutionManager.RequestAccessAsync();
var builder = new BackgroundTaskBuilder();
builder.Name = "PushBackgroundTask";
builder.TaskEntryPoint = typeof(NotificationActionBackgroundTask.NotificationActionBG).FullName;
builder.SetTrigger(new Windows.ApplicationModel.Background.PushNotificationTrigger());
BackgroundTaskRegistration task = builder.Register();
}
This is my app's Package.appxmanifest code,
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="NotificationActionBackgroundTask.NotificationActionBG">
<BackgroundTasks>
<Task Type="pushNotification" />
</BackgroundTasks>
</Extension>
</Extensions>
回答1:
I have checked our code and config file, it seems that they should be correct, in order to let your Backgroundtask's name show in your Lifecycle events windows for your debugging, you need to click the "Suspend" event inside the Lifecycle event windows after you have registered the Backgroundtask. Then your Backgroundtask's name will show inside the Lifecycle events windows.
If it still does not work, I wonder if you have registered the Backgroundtask correctly before you do the debugging, only if we have registered the Backgroundtask successfully, then we can debug the Backgroudtask using the Lifecycle event. If so, could you please try to put a breakpoint inside the register method to see what happens?
For more information, please check the following two articles:
Debug a background task.
Background tasks triggered by raw notifications.
来源:https://stackoverflow.com/questions/38199110/background-task-using-pushnotificationtrigger