Background Task using PushNotificationTrigger()

心不动则不痛 提交于 2020-01-05 08:05:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!