I need to implement geofencing background task in my App. I've used mainly code from geofencing samples at MSDN. No matter what I'm doing it always end in App.g.i.cs debugger while trying to get BackgroundExecutionManager access.
public async static void Register()
{
if (!IsTaskRegistered())
{
var result = await BackgroundExecutionManager.RequestAccessAsync();
var builder = new BackgroundTaskBuilder();
builder.Name = TaskName;
builder.TaskEntryPoint = typeof(GeofenceTask).FullName;
builder.SetTrigger(new LocationTrigger(LocationTriggerType.Geofence));
builder.Register();
}
}
It never goes into var builder = new BackgroundTaskBuilder(); - always ending before. What possibly am I doing wrong?
Btw. IsTaskRegistered() is working OK, but just in case:
public static bool IsTaskRegistered()
{
var taskRegistered = false;
var entry = BackgroundTaskRegistration.AllTasks.FirstOrDefault(kvp => kvp.Value.Name == TaskName);
if (entry.Value != null)
taskRegistered = true;
return taskRegistered;
}
This can occur if you haven't declared any background task in the application manifest.
You need to go to the Declarations tab, then add a new Background Task with Location type, and fill it's "Entry point" like this: "BackgroundTask.GeofenceTask". The "Executable" and "Start page" should be empty.