I'm using C# and Microsoft.Win32.TaskScheduler.dll to create dynamic scheduled tasks. No problem to set a date for a specific scheduled Month date :
TaskService ts = new TaskService();
TaskDefinition tsDef = ts.NewTask();
(...)
DateTime scheduleDateTime = new DateTime(2024, 12, 31, 23, 59, 0);
m_Logger.SendMessage("Trigger Monthly...");
MonthlyTrigger objMonthlyTrigger = new MonthlyTrigger();
objMonthlyTrigger.DaysOfMonth = new int[] { scheduleDateTime.Day };
objMonthlyTrigger.StartBoundary = scheduleDateTime;
objMonthlyTrigger.EndBoundary = DateTime.MaxValue;
tsDef.Triggers.Add(objMonthlyTrigger);
My question is about to use the setting for a trigger "on a schedule Monthly" for examples :
How can I do that ? Thanks per advance for your help
You need MonthlyDOWTrigger
. The native object is documented here, and the .NET wrapper is here.
MonthlyDOWTrigger objMonthlyTrigger = new(DaysOfTheWeek.Sunday | DaysOfTheWeek.Saturday, weeksOfMonth: WhichWeek.SecondWeek | WhichWeek.ThirdWeek)
{
StartBoundary = scheduleDateTime,
EndBoundary = DateTime.MaxValue,
};
tsDef.Triggers.Add(objMonthlyTrigger);