How to determine the schedule at which a background task is to be performed

1

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

    
asked by anonymous 23.08.2015 / 01:54

1 answer

0

It is not possible to determine a specific time for a background task to be executed. You can use a timer trigger to specify the time interval between background task runs, respecting the minimum time of 15 minutes, is a rule. Here is an example of using the timer trigger:

                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                taskBuilder.Name = nameof(BackgroundClassName);
                taskBuilder.TaskEntryPoint = typeof(BackgroundClassName).ToString();
                // min 15 minutes
                taskBuilder.SetTrigger(new TimeTrigger(15, false));
                BackgroundTaskRegistration registration = taskBuilder.Register();

If you want to see other triggers and how to use background tasks efficiently access this MVA in Portuguese ( link )

    
14.12.2015 / 13:29