简体   繁体   English

UWP后台任务未执行

[英]UWP Background Task is not executing

I am new to uwp and I am trying to learn how to make a background task. 我是uwp的新手,我正在努力学习如何完成后台任务。 I tried to follow the instruction I have found online but cannot seem to get it working. 我试着按照我在网上找到的指示,但似乎无法使其正常工作。 I am not getting an explicit error but my background task is not writing to the debug console. 我没有得到明确的错误,但我的后台任务没有写入调试控制台。 Any help would greatly be appreciated. 任何帮助将不胜感激。

This is my main xaml 这是我的主要xaml 在此输入图像描述

This is my mainpage class 这是我的主页课 在此输入图像描述

This is my Background Task in the Windows Runtime Component Project("MyBackgroundTask") 这是Windows运行时组件项目中的后台任务(“MyBackgroundTask”) 在此输入图像描述

This is my manifest 这是我的表现 在此输入图像描述

This is before I press the button 这是在我按下按钮之前 在此输入图像描述

This is after I press the button 这是在我按下按钮之后 在此输入图像描述

Currently, you are using ApplicationTrigger for your BackgroundTask. 目前,您正在为BackgroundTask使用ApplicationTrigger This will allow you to start executing your backgroundtask programmatically. 这将允许您以编程方式开始执行后台任务。

But you need to call ApplicationTrigger.RequestAsync or ApplicationTrigger.RequestAsync(ValueSet) to start invoking your background task. 但是您需要调用ApplicationTrigger.RequestAsyncApplicationTrigger.RequestAsync(ValueSet)来开始调用后台任务。

So, store your trigger globally, and call trigger.RequestAsync after registration(eg in another button click event handler) will solve the problem: 因此,全局存储您的触发器,并在注册后调用trigger.RequestAsync (例如在另一个按钮单击事件处理程序中)将解决问题:

ApplicationTrigger trigger;
...
private async void btnTrigger_Click(object sender, RoutedEventArgs e)
{
    await trigger.RequestAsync();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM