Search code examples
.net.net-corehangfire

How to run hangfire on a specific day in a week


I want to run a schedule on thursday 12:00 a.m. every week how to write the cron?


Solution

  • In this case, you would want the Cron.Weekly(DayOfWeek, Hour).

    The IRecurringJobManager interface has a method for adding or updating your tasks (AddOrUpdate). That method contains an argument for specifying a timeframe.

    If you're using a startup project, you would add your task like so:

    fooJobManager.AddOrUpdate("TaskName", exampleFunctionToRun, Cron.Weekly(DayOfWeek.Thursday, 0));