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

NextRunTime is Never!

Feb 4, 2012 at 6:46 AM

Hi

I added your wonderful scheduler to my windows application and it works perfect in Vista Home Edition development machine. The problem is, once I install or deploy the application to Windows XP professional box, NextRunTime comes up as NEVER! Please advise. Below is the code I used.

 

    // Get the service on the local machine
        using (TaskService ts = new TaskService())
        {
            // Create a new task definition and assign properties
            TaskDefinition td = ts.NewTask();
            td.RegistrationInfo.Description = description;
            td.Settings.DeleteExpiredTaskAfter = new TimeSpan(7, 0, 0, 0, 0);
            //td.Settings.RestartInterval = new TimeSpan(0, 3, 0); // throw exception with windows XP
            //td.Settings.RestartCount = 3;
            td.Settings.WakeToRun = true;
           
            TimeTrigger trigger = new TimeTrigger();
            trigger.StartBoundary = executionTime;           
            trigger.EndBoundary = executionTime.AddHours(1.0);

            td.Triggers.Add(trigger);           
           
            string execFolder = "C://Program Files/MegapixelsServer/MegapixelsScheduler.exe";
            td.Actions.Add(new ExecAction(execFolder, taskName, null));

            ts.RootFolder.RegisterTaskDefinition(taskName, td);         
        }

Coordinator
Feb 5, 2012 at 4:22 AM

I have tested this code and the only thing I can see that would be causing a problem is the initial value of 'executionTime'. Using DateTime.Now for that value works on my system. To deal with your commented out lines, you can use the following code.

using (TaskService ts = new TaskService())
{
    // Create a new task definition and assign properties
    TaskDefinition td = ts.NewTask();
    td.RegistrationInfo.Description = description;
    td.Settings.DeleteExpiredTaskAfter = new TimeSpan(7, 0, 0, 0, 0);
    if (ts.HighestSupportedVersion >= new Version(1, 2))
    {
        td.Settings.RestartInterval = new TimeSpan(0, 3, 0);
        td.Settings.RestartCount = 3;
    }
    td.Settings.WakeToRun = true;
   
    TimeTrigger trigger = new TimeTrigger();
    trigger.StartBoundary = executionTime;
    trigger.EndBoundary = executionTime.AddHours(1.0);

    td.Triggers.Add(trigger);
   
    string execFolder = "C://Program Files/MegapixelsServer/MegapixelsScheduler.exe";
    td.Actions.Add(new ExecAction(execFolder, taskName, null));

    ts.RootFolder.RegisterTaskDefinition(taskName, td);
}