Unable to set Advanced Setting Property Repetition Duration and Interval

Sep 9, 2009 at 7:41 PM

Hello,

I  was Unable to set Advanced Setting Property  Repetition Duration and Interval to appropriate value using the code below.

 

TaskService ts = new TaskService();
TaskDefinition td = ts.NewTask();
WeeklyTrigger weeklyTrigger = new WeeklyTrigger();
 weeklyTrigger.DaysOfWeek = DaysOfTheWeek.Saturday;
 weeklyTrigger.WeeksInterval = 2;
 weeklyTrigger.Repetition.Duration = TimeSpan.FromMinutes(120);
 weeklyTrigger.Repetition.Interval = TimeSpan.FromMinutes(10);
 td.Triggers.Add(weeklyTrigger);
 td.Actions.Add(new ExecAction("notepad.exe", "E:\\Temp\\Test.log", null));    
 ts.RootFolder.RegisterTaskDefinition("Test", td);

I today downloaded the  latest code of Task service  from the   website.

Could you please   let  me know where I am  going wrong?

Thanks,

-Sanjay Cyriac

Sep 16, 2009 at 3:05 PM

I also encountered the same problem (I'm using the 1.3.1 version).

It seems that the Repitition property is ignored.

Coordinator
Sep 17, 2009 at 1:14 AM

Will you download and compile the latest source and let me know if you still see the problem?

Sep 17, 2009 at 7:43 AM
Edited Sep 17, 2009 at 8:59 AM

Now I will download and compile the latest source, but with the stable release 1.3.1 I tried this code and it runs very well.

However thank you very much for your great work!

internal void newBackupTask()
        {
            taskDefinition = backupTaskService.NewTask();
            taskDefinition.RegistrationInfo.Description = LocRM.GetString(taskDescription);
            taskDefinition.Settings.DisallowStartIfOnBatteries = disallowStartIfOnBatteriesFlag;
            if (Environment.OSVersion.Version.Major >= 6)
            {
                taskDefinition.Settings.Priority = System.Diagnostics.ProcessPriorityClass.BelowNormal;
                taskDefinition.Settings.StartWhenAvailable = true;
                taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
            }
            DailyTrigger dailyTrigger = (DailyTrigger)taskDefinition.Triggers.Add(new DailyTrigger
            {
                DaysInterval = Int16.Parse(daysOfIntervalFlag)
            });
            dailyTrigger.Repetition.Interval = TimeSpan.FromMinutes(int.Parse(everyTotMinutes));
            dailyTrigger.Repetition.Duration = TimeSpan.FromSeconds(86399);
            taskDefinition.Actions.Add(new ExecAction(Application.ExecutablePath, argumentsTask, null));
            backupTaskService.RootFolder.RegisterTaskDefinition(titleOfTask, taskDefinition);
        }

Sep 17, 2009 at 8:10 AM
Edited Sep 17, 2009 at 8:58 AM

Well done! The last source code runs very well on Vista/Windows 7! You fixed the bug! Many thanks!

This is my new code (It runs well only with the last source code)

internal void newBackupTask()
        {
            taskDefinition = backupTaskService.NewTask();
            taskDefinition.RegistrationInfo.Description = LocRM.GetString(taskDescription);
            taskDefinition.Settings.DisallowStartIfOnBatteries = disallowStartIfOnBatteriesFlag;
            if (Environment.OSVersion.Version.Major >= 6)
            {
                taskDefinition.Settings.Priority = System.Diagnostics.ProcessPriorityClass.BelowNormal;
                taskDefinition.Settings.StartWhenAvailable = true;
                taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
            }
            DailyTrigger dailyTrigger = new DailyTrigger();
            dailyTrigger.DaysInterval = Int16.Parse(daysOfIntervalFlag);
            dailyTrigger.Repetition.Interval = TimeSpan.FromMinutes(int.Parse(everyTotMinutes));
            dailyTrigger.Repetition.Duration = TimeSpan.FromHours(24); //TimeSpan.FromSeconds(86399);
            taskDefinition.Triggers.Add(dailyTrigger);
            taskDefinition.Actions.Add(new ExecAction(Application.ExecutablePath, argumentsTask, null));
            backupTaskService.RootFolder.RegisterTaskDefinition(titleOfTask, taskDefinition);
        }

 

 

Excuse me, but for Windows XP? Repetition properties is not supported by TaskScheduler 1.0?

 

EDIT: Great news! this new source code fixed the repetition bug with Windows XP. Now it runs well on Windows XP also.

Coordinator
Sep 17, 2009 at 4:16 PM
Edited Sep 17, 2009 at 4:43 PM

Thanks for testing it for me. I'm glad its working now. I will post the binary later today so everyone else doesn't have to compile the code. In your honor, the build version will be 1.4.0.783.

Sep 17, 2009 at 7:18 PM

OMG! I'm honored! Thank you so much!

May 19, 2010 at 1:10 PM

Hey guys, first of all thanks for this great work! Saved me hours! Haha

This really doesn't deal with this .dll but does anyone get 'Value does not fall in the expected range' when you try to use the TimeSpan.FromMinutes() method?? (or any of the From____() methods)

Thank you!

 

May 19, 2010 at 2:07 PM

oops, I forgot to add the duration value! Thank you! ;)