This project has moved. For the latest updates, please go here.

"StartWhenAvailable" not checked in Scheduler

Topics: Examples
Apr 7, 2016 at 11:28 PM
Hey there,

First of all, thanks for making this Wrapper. It's amazing.

I need to change desktop background every day based on time user picks. If machine is not working I need this task to start after user logs on at some point.

This is the code that I have at the moment :
using (TaskService taskSer = new TaskService())
            {
                TaskDefinition td = taskSer.NewTask();
                DailyTrigger dt = new DailyTrigger();
                dt.StartBoundary = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, startHour.Hours, startHour.Minutes, startHour.Seconds);

                taskSer.AddTask("Task", dt, new ExecAction(execPath));

                td.Settings.StartWhenAvailable = true;
                td.Settings.Compatibility = TaskCompatibility.V2_3;
                td.Settings.RestartInterval = TimeSpan.Zero;
            }
However, when I go to Task Scheduler, Settings tab, checkbox for starting the task after missing it, is not checked.

How can I set "StartWhenAvailable" checkbox marked through the code ?

I did check Discussions and only found one topic which covered this question, but it doesn't apply to me as I tried already to set RestartInterval to TimeInterval.Zero. I need this task to be infinite, so I'm not sure how would I set EndBoundry in that case ?

Thanks,
S. M.
Coordinator
Apr 8, 2016 at 5:50 PM
Close, but you mixed the quick model (using AddTask) with the full control model (which uses TaskDefinition and RegisterTaskDefinition). Your corrected code would be:
TaskDefinition td = TaskService.Instance.NewTask();
// Setup and add trigger
DailyTrigger dt = new DailyTrigger();
dt.StartBoundary = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, startHour.Hours,
    startHour.Minutes, startHour.Seconds);
td.Triggers.Add(dt);
// Setup and add action
td.Actions.Add(execPath);
// Add settings
td.Settings.StartWhenAvailable = true;
td.Settings.Compatibility = TaskCompatibility.V2_3;
td.Settings.RestartInterval = TimeSpan.Zero;
// Register definition
TaskService.Instance.RootFolder.RegisterTaskDefinition("Task", td);
Marked as answer by Srki94 on 4/8/2016 at 11:45 AM
Apr 8, 2016 at 7:47 PM
Thank you so much dahall !

I realized my mistake as well now :)

I'm sure this topic will be of use to someone else too.

Marked as answer.