This project has moved and is read-only. For the latest updates, please go here.

How Do I Add All Checked Days To The DAYofWeek Setting? & Add how do i Add Repetition

Sep 17, 2009 at 6:25 AM
Edited Sep 17, 2009 at 6:26 AM

how can i check my 7 checkbox's and then add each checked to the DayofWeek setting

i tried this but it didn't work


td.Triggers.Add(new WeeklyTrigger() { WeeksInterval = 1, StartBoundary = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(comboBox3.Text), Convert.ToInt32(comboBox4.Text), 0), DaysOfWeek = (checkBox1.Checked == true) ? DaysOfTheWeek.Sunday : null | (checkBox2.Checked == true) ? DaysOfTheWeek.Monday : null | (checkBox3.Checked == true) ? DaysOfTheWeek.Tuesday : null | (checkBox4.Checked == true) ? DaysOfTheWeek.Wednesday : null | (checkBox5.Checked == true) ? DaysOfTheWeek.Thursday : null | (checkBox6.Checked == true) ? DaysOfTheWeek.Friday : null | (checkBox7.Checked == true) ? DaysOfTheWeek.Saturday : null });
and how do i add repetition to that?
i tried to create a repetition pattern then set Repetition = RP but it says that Repetition is read-only and there's not a way to select Repetition.Interval or Repetition.Duration.
Sep 17, 2009 at 9:17 AM

For the repetition property see this thread:

and after download this nightly build because in the stable release there is a bug (repetition property is ignored):



Sep 17, 2009 at 5:12 PM

Wow! Really long code statement. As alex783 mentioned, the source code drop from Sep. 16, 2009 contains the fixes to allow repetition to work.
I will be pushing that code out in binary form later this week. To answer your question about DaysOfWeek and setting the Repetition values, I would use this code:

WeeklyTrigger wt = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger() { WeeksInterval = 1 });
wt.StartBoundary = DateTime.Today + new TimeSpan(Convert.ToInt32(comboBox3.Text), Convert.ToInt32(comboBox4.Text), 0);
wt.DaysOfWeek = (checkBox1.Checked) ? DaysOfTheWeek.Sunday : 0 |
	(checkBox2.Checked) ? DaysOfTheWeek.Monday : 0 |
	(checkBox3.Checked) ? DaysOfTheWeek.Tuesday : 0 |
	(checkBox4.Checked) ? DaysOfTheWeek.Wednesday : 0 |
	(checkBox5.Checked) ? DaysOfTheWeek.Thursday : 0 |
	(checkBox6.Checked) ? DaysOfTheWeek.Friday : 0 |
	(checkBox7.Checked) ? DaysOfTheWeek.Saturday : 0;
wt.Repetition.Interval = TimeSpan.FromMinutes(Convert.ToDouble(textBox1.Text));
wt.Repetition.Duration = TimeSpan.FromMinutes(Convert.ToDouble(textBox2.Text));
Sep 17, 2009 at 11:35 PM

i tried the

wt.DaysOfWeek = (checkBox1.Checked) ? DaysOfTheWeek.Sunday : 0 |
(checkBox2.Checked) ? DaysOfTheWeek.Monday : 0 |
(checkBox3.Checked) ? DaysOfTheWeek.Tuesday : 0 |
(checkBox4.Checked) ? DaysOfTheWeek.Wednesday : 0 |
(checkBox5.Checked) ? DaysOfTheWeek.Thursday : 0 |
(checkBox6.Checked) ? DaysOfTheWeek.Friday : 0 |
(checkBox7.Checked) ? DaysOfTheWeek.Saturday : 0;
it gives me build error's of
"Operator '|' cannot be applied to opernds of type 'int' and 'bool'"
bug? or just won't work?
Sep 18, 2009 at 12:30 AM

Have you tried "||" instead "|" ?  It is the "conditional OR" operator.

Sep 18, 2009 at 3:55 AM

Same thing!

"Operator '||' cannot be applied to operands of type 'int' and 'bool'"

Sep 18, 2009 at 8:00 AM
Edited Sep 18, 2009 at 8:23 AM

oh! how can i disable the "Stop the task if it runs more than" option?

i tried 

td.Settings.ExecutionTimeLimit =




td.Settings.ExecutionTimeLimit = 0;

td.Settings.ExecutionTimeLimit = TimeSpan.FromMinutes(0);

Sep 21, 2009 at 6:36 AM

Sorry my post couldn't be compiled. Here is code that works. This is really just working with enums.

wt.DaysOfWeek = (DaysOfTheWeek)((checkBox1.Checked ? (int)DaysOfTheWeek.Sunday : 0) |
   (checkBox2.Checked ? (int)DaysOfTheWeek.Monday : 0) |
   (checkBox3.Checked ? (int)DaysOfTheWeek.Tuesday : 0) |
   (checkBox4.Checked ? (int)DaysOfTheWeek.Wednesday : 0) |
   (checkBox5.Checked ? (int)DaysOfTheWeek.Thursday : 0) |
   (checkBox6.Checked ? (int)DaysOfTheWeek.Friday : 0) |
   (checkBox7.Checked ? (int)DaysOfTheWeek.Saturday : 0));

To answer your other question, to disable "Stop the task if it runs more than" option, you actually are trying to set it to "Infinite", so try:

td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
Apr 22, 2010 at 11:40 AM
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;

This setting does not take effect ...
Set is still 3 days
How can I do?

Apr 26, 2010 at 5:44 PM

A few questions: 1) After you make the change to ExecutionTimeLimit, are you re-registering the task definition to save it? See example on Home page if you need to see how to do this. 2) Which version of Windows are you running the code against?

Apr 29, 2010 at 3:33 AM

my code :

I am not fully aware of, please remind.

string tmp = txtCommand[1].Trim('\"');
string[] daytime = tmp.Split('|'); //date and time
MSTask.TaskService ts = new MSTask.TaskService();
MSTask.TaskDefinition td = ts.NewTask();
for (int i = 0; i < daytime.Length; i++)
{ string[] strDT = daytime[i].Split(','); MSTask.WeeklyTrigger wt = new MSTask.WeeklyTrigger(); if (strDT[0] == "1") //running date and time { wt.DaysOfWeek = (MSTask.DaysOfTheWeek)(System.Math.Pow(2, i)); //day wt.StartBoundary = DateTime.Parse(strDT[1]); td.Triggers.Add(wt); } } td.Settings.ExecutionTimeLimit = TimeSpan.Zero; td.RegistrationInfo.Description = "Task ShutDown"; td.Actions.Add(new MSTask.ExecAction("shutdown.exe", "-s -f -t 30", null)); ts.RootFolder.RegisterTaskDefinition("TaskShutDown", td);

My OS is Vista SP2 & XP SP3
May 3, 2010 at 12:15 AM

Ok. Found the bug in ExecutionTimeLimit. The documentation says setting it to 'null' will result in infinite. The truth is that setting it to null makes it go to the default of 72 hours. Setting it to 'PT0S' makes it go to infinite. I have corrected the code and will include it in the next build.

May 4, 2010 at 3:50 AM

This set is successful in task v2 (Vista SP2)

But in the task v1 (XP SP3) is wrong out of a warning message in the [If executed _ will stop working] in the time setting should be greater than zero

Can I suggest a more simple? If We give property to "ExecutionTimeLimit.enabled = false" possible?


Aug 19, 2011 at 8:58 PM

Hi dahall,

i am using ver 1.6.3, the latest version of the dll and i cant uncheck the "Stop task if it runs for.." options in general settings. In your post you mentioned about setting it to 'PT0S' for infinite. But the poroperty requires an Timespan.

what do i need to set it to infinite or uncheck that option?

Aug 20, 2011 at 1:13 AM

To answer your other question, to disable "Stop the task if it runs more than" option, you actually are trying to set it to "Infinite", so try:

td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
Aug 20, 2011 at 8:17 AM

Yes, have tried that and on doing so, in the minutes and seconds i see zero and when i open the task it complains that the values are invalid and prompts for atleast 1 sec time limit. 

This is offcourse not going to help my cause. I dont know, if min=0 and sec=0 settings will make it infinite or not. but isnt there a way to completely turn it off somehow?

Aug 20, 2011 at 1:44 PM

koushikc: Are you opening the task in the Windows Task Scheduler tool or are you using my library's controls?

Aug 20, 2011 at 2:37 PM

I am using the windows task scheduler tool. Actually i am creating some tasks in my network machines from my pc and then i am trying to see the tasks with the windows task schedular tool.

Aug 21, 2011 at 11:52 PM

You have found a bug with Microsoft's Task Scheduler tool and V1 compatible tasks. If you will create the TaskService with the forceV1 parameter set to false the UI will work fine. If the task is created on an XP or earlier system, you can only create a V1 task and the UI will have the problem. The actual task has no execution time limit. You can check that programatically.

Aug 22, 2011 at 5:22 AM

Thanks dahall.

So, what you mean is there is no way to create a generic task (because i dont know the machine type, i will be installing the task) ? If so, what happens if i do a generic task with forceV1=false? In that case will the the task that is created in XP machine will work or not?

I will give it a try myself also.

Another query : by execution time limit what is actually meant? Does that mean that a task becomes invalid and will not be executed after the time frame? Or, if a task is running continuously for that time frame, it will stop after that time frame?

Actually , i am creating an OnIdle task. In the OnIdle condition my custom program gets started by the task. Now when Idle condition ceases, the tasks stops. So, do you think that i can have problems with the execution limit? Am i right in my asumption that my exe will stop executing only when i have crossed the time limit. But after that when machine becomes Idle again (if it does), the task will again fire.

Also, if possible can you tell me, on what condition the system determines whether it is idle or not? i can understand that one would be mouse keyboard activity for specified time frame. But is cpu utilization also taken into account? If so, what is the threshold? Is it documented anywhere for task schedular?

Aug 22, 2011 at 4:15 PM

I'm not sure what you mean by "generic task". If you create the TaskService instance with the forceV1 parameter set to true, then all tasks will be V1 compatible. If you leave that parameter set to false, then tasks created on XP and earlier will be V1 and on Vista and later will be V2.

Execution Time Limit is defined as the time that a task is allow to run before it is terminated.

You are correct in that the OnIdle task will fire when the system is idle (defined as no user interactions) for defined period of time.

Aug 24, 2011 at 2:45 PM

Thanks dahall for all your communication and help. I would like to know another small thing. Is it possible to run a already scheduled task in remote machine with the wrapper?

Aug 24, 2011 at 2:48 PM

Sorry for a repeation query : i found your answer in one of the discussion :

will try this as per you :

using (TaskService ts = new TaskService())
   string task = rdr["TaskName"].ToString();
   // This will find it even if its down in a folder. Alternately you could call:
   // Task t = ts.GetTask(task);
   Task t = ts.FindTask(task);
   if (t != null)
Aug 24, 2011 at 3:12 PM


i tried the code above to run a already scheduled service, but the task didnt start in remote machine, though t was not null and was executed.

Can you pls help me out?

Aug 26, 2011 at 7:29 AM

To connect to a remote machine, you must connect to it using the parameters to the TaskService constructor. You can then use the remainder of your code as is to run the task.

Aug 30, 2011 at 8:22 PM


The connection (creation and running) of task is hapenning perfectly in my domain computers. But how to connect to remote task service of a machine which is not in the domain, but belongs to a workgroup?

I have the credentials with me, but what to pass in the domain param?

Aug 31, 2011 at 3:11 AM

If the account is a local machine account, then you pass in the name of the machine.

Aug 31, 2011 at 5:54 AM

My remote machine name is "Test1"

The user id used is say "Test1\UID" and we have a password for it "PWD"

Now in the call i am sending these 

user : UID

password :PWD

machine : Test1

domain: Test1

But while accessing the task service, i am getting an exception.

Feb 14, 2012 at 6:55 AM

Hi Dahall,

I try to set

td.Settings.ExecutionTimeLimit = TimeSpan.Zero;

on an XP machine but it cannot set the time to infinite. I can set on Windows Server 2008 machine.

Is there anyway to set ExecutionTimeLimit to infinite on an XP machine? I also forceV1 parameter set to true but no result.


Feb 14, 2012 at 7:29 AM

Hi thientan0206,

I also verified that setting ExecutionTimelimit to TimeSpan.Zero doesnt make it Infinite in XP/windows7.

Alternatively you can try

 td.Settings.ExecutionTimeLimit = new TimeSpan(42949672950000);

Feb 16, 2012 at 1:29 AM

Thanks koushikc. It works.