Search code examples
c#.nethangfire

how to pause hangfire's job? between certain hours


I want have hangfire jobs not working if the time is between 8:00 pm & 8:00 am between these hours I wanna hangfire jobs idle. any ideas?


Solution

  • You need to provide a correct cron expression to the recurring job which will fire your desired code.

    For example, this cron expression runs the job every hour from 8AM to 8PM.

    0 0 8-20 ? * * *
    

    Cron is a "whitelist" approach (i.e. when to work) than "blacklist" approach as in your questions (when not to work). Hangfire runs recurring jobs based on cron expressions.