I have a background task and it is supposed to trigger when there is some change in position because it is set with Geofence trigger.
builder.SetTrigger(new LocationTrigger(LocationTriggerType.Geofence));
private static async Task<string> LocationUpdateHelper()
{
try
{
var taskRegistered = false;
string myTaskName = "LocationUpdateTask";
foreach (var cur in BackgroundTaskRegistration.AllTasks)
if (cur.Value.Name == myTaskName)
{
taskRegistered = true;
break;
}
if (taskRegistered != true)
{
await BackgroundExecutionManager.RequestAccessAsync();
var builder = new BackgroundTaskBuilder();
builder.Name = "LocationUpdateTask";
builder.TaskEntryPoint = "SmartRuntimes.LocationUpdateTask";
builder.SetTrigger(new LocationTrigger(LocationTriggerType.Geofence));
try
{
builder.Register();
Debug.WriteLine("GeoFence Task Registered");
}
catch (Exception ex)
{
Debug.WriteLine("GeoFence Task Failed : " + ex.Message.ToString());
}
}
return "success";
}
catch (Exception ex)
{
return "";
}
}
And LocationUpdateTask class is:
public sealed class LocationUpdateTask : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
string taskName = taskInstance.Task.Name;
var deferral = taskInstance.GetDeferral();
await BackgroundTaskHelper.UpdateLocation();
deferral.Complete();
}
}
My question is:
- Does this background task triggers when there is change in position?
- How much distance needs to change for triggering that background task?
Thanks!