Vaibhav Patil
Vaibhav Patil

Reputation: 37

I want A Quartz That Execute On Every month of 1st day?

ITrigger trigger = TriggerBuilder.Create()
                       .StartAt(DateTime.Today.AddMinutes(1))
                          .WithIdentity("trigger1", "group1")
                           .StartNow()
                          .WithSimpleSchedule(x => x
                              .WithIntervalInSeconds(10)
                          .WithRepeatCount(0)
                            )
                      .Build();

I want Trigger That Execute on Every month OF 1st day

Upvotes: 3

Views: 8059

Answers (2)

Kristof Neirynck
Kristof Neirynck

Reputation: 4162

I was looking for a way to execute on the first weekday of the month this in a java quartz CronTrigger and ended up on this page. Not sure if this works with Quartz.Net, but java quartz supports the notation 0 7 1 1W * ? for first weekday of the month. I'm writing it down here for future me.

0 7 1 1W * ?:

  • Seconds 0
  • Minutes 7
  • Hours 1
  • Day-of-month 1W weekday nearest the first of the month
  • Month *
  • Day-of-Week ? no specific value

Also see the javadoc of org.quartz.CronExpression.

Upvotes: 0

LeftyX
LeftyX

Reputation: 35587

You've got two options there. You can use a cron expression and use WithCronSchedule in your trigger using this cron expression:

0 0 12 1 1/1 ? *

this is the code:

ITrigger trigger = TriggerBuilder
    .Create()
    .StartNow()
    .WithIdentity("trigger1", "myGroup")
    .WithCronSchedule("0 0 12 1 1/1 ? *")
    .Build();

Notice this trigger would start at midday.

You can check the cron expression and customize it using this helpful tool.

Option 2 is a schedule using CronScheduleBuilder.MonthlyOnDayAndHourAndMinute:

ITrigger trigger = TriggerBuilder
    .Create()
    .StartNow()
    .WithIdentity("trigger1", "myGroup")
    .WithSchedule(CronScheduleBuilder.MonthlyOnDayAndHourAndMinute(1, 12, 0))
    .Build();

NOTES:

Cron expressions in Quartz.Net are made up of 7 sub-expressions:

1. Seconds
2. Minutes
3. Hours
4. Day-of-Month
5. Month
6. Day-of-Week
7. Year (optional field)

Upvotes: 5

Related Questions