I'm developing a WinRT Windows Phone 8.1 app, and I'm trying to implement a background task. After a lot of research, I was able to produce a code that should work, but when I try to run it, the debugger exits, no error, just exits... I tried with Lifecycle Events menu and by setting a timezone trigger, on both instances, i get the same result.
Details: I created a new project using Windows Runtime Component (Windows Phone) template, then edited the file to be a simple BackgroundTask:
namespace RSSReader.Tasks
{
public sealed class GetFeed
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
// Will do stuff...
}
}
}
Registered it on the Package.appxmanifest, on Declarations tab, created a Background Tasks declaration, ticked System event, and set the Entry point as RSSReader.Tasks.GetFeed
.
Then, on the MainPage I added the following:
private async void registerTask()
{
string taskName = "FeedChecker";
var bgAccStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (bgAccStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
bgAccStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
{
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == taskName)
{
return;
}
}
var builder = new BackgroundTaskBuilder();
var trigger = new SystemTrigger(SystemTriggerType.TimeZoneChange, false);
builder.Name = taskName;
builder.TaskEntryPoint = typeof(Tasks.GetFeed).FullName;
builder.SetTrigger(trigger);
var registration = builder.Register();
}
}
It register the task, but when I change the timezone, my app is gone and the debugger exits...