I just downloaded the Sample from https://code.msdn.microsoft.com/windowsapps/Background-Task-Sample-9209ade9 and tried running the windows phone 8.1 project. The program runs but there is no background task that happens even when I made the changes to trigger the event. I also don't think its getting registered to run as a background task as I don't get any request to add the app to Lock screen. And I couldn't manually add the app to lock screen. Note: Using Lumia 730 with 8.1 Denim.
I also tried to write a sample program myself with silverlight 8.1 and background as RT component.
if (BackgroundTaskRegistration.AllTasks.Any(task => task.Value.Name == name))
{
// One register it once
return;
}
var builder = new BackgroundTaskBuilder();
var trigger = new SystemTrigger(SystemTriggerType.UserAway, false);
builder.Name = name;
builder.TaskEntryPoint = typeof(MyBackgroundTask.BackClass).FullName; builder.SetTrigger(trigger);
await BackgroundExecutionManager.RequestAccessAsync();
BackgroundTaskRegistration registration = builder.Register();
registration.Completed += RegistrationOnCompleted;
Here too I'm getting an exception on the line
BackgroundTaskRegistration registration = builder.Register();
The exception is runtime which states
> A first chance exception of type 'System.Exception' occurred in
> Project1.DLL