问题描述
对于 TimerTigger() 后台任务工作正常.当我想调试时,我可以从 Lifecycle Events 中进行.但是当我使用 PushNotificationTrigger() 时,我无法调试后台任务.我不明白我做错了什么,请帮忙.这是我在调试时在生命周期事件中得到的.这就是我为原始通知注册后台任务的方式,
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();
}
这是我的应用程序的 Package.appxmanifest 代码,
This is my app's Package.appxmanifest code,
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="NotificationActionBackgroundTask.NotificationActionBG">
<BackgroundTasks>
<Task Type="pushNotification" />
</BackgroundTasks>
</Extension>
</Extensions>
推荐答案
我已经检查了我们的代码和配置文件,看起来它们应该是正确的,以便让您的 Backgroundtask 的名称显示在您的 Lifecycle 事件窗口中以进行调试,您需要在注册后台任务后单击 Lifecycle 事件窗口内的 暂停" 事件.然后您的后台任务的名称将显示在生命周期事件窗口中.
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.
如果还是不行,请问您在调试前是否正确注册了Backgroudtask,只有我们成功注册了Backgroudtask,才能使用Lifecycle事件调试Backgroudtask.如果是这样,能否请您尝试在 register 方法中放置一个断点,看看会发生什么?
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:
这篇关于使用 PushNotificationTrigger() 的后台任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!