I'm programming for Windows 10, and at certain times in a day I want my background task to be addressed.
Here is my registration code:
from the home screen:
var trigger = new SystemTrigger(SystemTriggerType.TimeZoneChange, false);
var condition = new SystemCondition(SystemConditionType.InternetAvailable);
var tarefa = RegistrarTarefasSegundoPlanoAsync.RegisterBackgroundTask(typeof(SalvaImagemTask).FullName, "SalvaImagemTask", trigger, condition);
RegisterBackgroundTask.cs
public static BackgroundTaskRegistration RegisterBackgroundTask(
string taskEntryPoint,
string name,
IBackgroundTrigger trigger,
IBackgroundCondition condition)
{
foreach (var cur in BackgroundTaskRegistration.AllTasks)
{
if (cur.Value.Name == name)
{
return (BackgroundTaskRegistration)(cur.Value);
}
}
var builder = new BackgroundTaskBuilder();
builder.Name = name;
builder.TaskEntryPoint = taskEntryPoint;
builder.SetTrigger(trigger);
if (condition != null)
{
builder.AddCondition(condition);
}
BackgroundTaskRegistration task = builder.Register();
return task;
}
Here's how it's registered in my manifest