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

Daily Trigger with weekdays set

Topics: Examples
Dec 10, 2012 at 4:32 PM

Hi All, 

I have been trying to create a daily trigger with week days set in it, but I couldn't find an example or a way to do it. something like following: 

 td.Triggers.Add(new DailyTrigger {

StartBoundary = dtCalendar.Value+dtTime.Value.TimeOfDay,                                   DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Tuesday | DaysOfTheWeek.Wednesday | DaysOfTheWeek.Thursday  | DaysOfTheWeek.Friday                                 });

Any help appreciated. 



Dec 10, 2012 at 9:22 PM

I think you are looking instead for a WeeklyTrigger. The following code will run the action every week on weekdays at the specified time.

td.Triggers.Add(new WeeklyTrigger(DaysOfTheWeek.Monday | DaysOfTheWeek.Tuesday | DaysOfTheWeek.Wednesday |
   DaysOfTheWeek.Thursday | DaysOfTheWeek.Friday) { StartBoundary = dtCalendar.Value+dtTime.Value.TimeOfDay });
Dec 11, 2012 at 11:41 AM
Edited Dec 11, 2012 at 11:42 AM

Hi dahall,

Thanks for your reply, 

No, I am not looking for weekly trigger. Though I had created a weekly trigger to work around my problem. I am specifically looking for a daily trigger within which I can specify week days, since my application interface allows user to create a weekly schedule for days as they desire as well as daily schedule for weekdays only, and in the background for daily schedule with weekdays I create a weekly trigger so as for weekly schedule. Now the problem is that when I go for reading the task created via my application interface so I would not be able to read it correctly since both schedule will create same type of trigger, so there is no way I can differentiate in between them. 

This is why I specifically need to create a daily trigger with weekdays set, and I thought this is possible because using windows task scheduler it gives you option to set a daily trigger with weekdays set. 



Dec 12, 2012 at 7:47 PM

I think if you look at the Task Scheduler system app, you will see that the weekly trigger (WeeklyTrigger) and the monthly days trigger (MonthlyDOWTrigger) are the only ones that support the specifying of week days. The DailyTrigger only supports an interval. You could always use the TaskDefinition.Data property to store something that will distinguish tasks for your application. It is supported across all operating systems.

Dec 13, 2012 at 4:16 PM

It didn't work. I set the data value to "W" or "D" as I create the schedule but when load the task for reading, I find blank string.  

Dec 14, 2012 at 5:08 AM

Under XP and earlier versions of the Task Scheduler, the Data and Documentation properties overlap. Are you setting the Documentation property? If not, then this does work. Make sure you register the task after setting the Data property and before reading it again.