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

DaysOfWeek

Jul 27, 2011 at 6:31 PM

Greetings, I have created code to retrieve a certain scheduled task and I am trying to return the DaysOfWeek that are set.

I know how to get the Trigger type of the targeted scheduled task - and determine whether it is weekly or daily...

MessageBox.Show(t.Definition.Triggers[0].TriggerType.ToString());

MessageBox.Show(t.Definition.Triggers[0].GetType().ToString());

But hitting a wall retrieving the DaysOfWeek once I determine the Trigger is weekly.

Any help would be greatly appreciated.

 

 

Coordinator
Jul 27, 2011 at 9:29 PM
WeeklyTrigger wt = t.Definition.Triggers[0] as WeeklyTrigger;
if (wt != null)
   return wt.DaysOfWeek;

Each trigger is actually specialized into a class that exposes the unique properties of that kind of trigger. Trigger is an abstract class from which all the trigger specializations are derived. WeeklyTrigger and DailyTrigger are two such specializations. By casting the abstract trigger to the appropriate specialization you can access the properties.