Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP Background Task is not executing

Tags:

c#

uwp

I am new to uwp and I am trying to learn how to make a background task. 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 enter image description here

This is my mainpage class enter image description here

This is my Background Task in the Windows Runtime Component Project("MyBackgroundTask") enter image description here

This is my manifest enter image description here

This is before I press the button enter image description here

This is after I press the button enter image description here

like image 399
David Wruck Avatar asked Aug 06 '16 18:08

David Wruck


1 Answers

Currently, you are using ApplicationTrigger for your BackgroundTask. 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.

So, store your trigger globally, and call trigger.RequestAsync after registration(e.g. in another button click event handler) will solve the problem:

ApplicationTrigger trigger;
...
private async void btnTrigger_Click(object sender, RoutedEventArgs e)
{
    await trigger.RequestAsync();
}
like image 113
Elvis Xia - MSFT Avatar answered Oct 18 '22 17:10

Elvis Xia - MSFT