Sometimes you may want to postpone a method invocation; for example, to send an email to newly registered users a day after their registration. To do this, just call the BackgroundJob.Schedule
method and pass the desired delay:
BackgroundJob.Schedule( () => Console.WriteLine("Hello, world"), TimeSpan.FromDays(1));
Hangfire Server periodically checks the schedule to enqueue scheduled jobs to their queues, allowing workers to execute them. By default, check interval is equal to 15 seconds
, but you can change it by setting the SchedulePollingInterval property on the options you pass to the BackgroundJobServer
constructor:
var options = new BackgroundJobServerOptions { SchedulePollingInterval = TimeSpan.FromMinutes(1) }; var server = new BackgroundJobServer(options);
If you are processing your jobs inside an ASP.NET application, you should perform the following steps to ensure that your scheduled jobs get executed at the correct time:
Disable Idle Timeout â set its value to 0
.
Use the application auto-start feature.
Hangfire documentation is licensed under the
CC BY 4.0.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4