Last Day of Month Only

Sep 7, 2012 at 5:01 AM
Edited Sep 7, 2012 at 5:04 AM

Would someone be kind enough to show me the necessary code to create a MonthlyTrigger on the last day of the month only?  MonthlyTrigger() no longer appears to be a valid constructor, and it appears MonthlyTrigger(int dayOfMonth, MonthsOfTheYear monthsOfYear) is the only valid constructor now, resulting in a forced providing of a hard day upon initialization.

The first parameter, dayOfMonth, must be a value between 1 and 31, which results in the DaysOfMonth property containing whatever value was passed at initiation. Null cannot be passed at initiation, and attempting to set DaysOfMonth to a null value after the constructor causes an exception.

I would prefer not to have to specify a hard date while initiating, as this would cause problems in February every leap year.

MonthlyTrigger mt = new MonthlyTrigger(31, this.Trigger.Months);
mt.RunOnLastDayOfMonth = true;


The code above results in a trigger for both the 31st and the Last day of the month.

Sep 7, 2012 at 2:10 PM
Edited Sep 7, 2012 at 2:13 PM
new MonthlyTrigger(1, this.Trigger.Months) { DaysOfMonth = new int[0], RunOnLastDayOfMonth = true };

I know that seems unintuitive, but it works. Effectively you are allowing the constructor to set the DaysOfMonth to a value (1 in this code) and then undoing it by setting it to an empty array. I made the change because I had other users that were using the default constructor and it was failing to register. Their argument was that a default constructor should never cause code to break and I agreed.

Sep 7, 2012 at 2:28 PM

Thank you very much. The above code does work.