I have a requirement that I think HangFire currently cannot satisfy. Please correct me if I’m wrong and such feature exists already in HangFire.
In .NET the Thread class has a constructor that receives a ParameterizedThreadStart delegate and by which you can specify an argument when calling thread’s Start() method. This argument in turn will be passed to the action you specified for the thread.
var myThread = new Thread(x => Console.WriteLine(x));
I think there should be an overload for RecurringJob.AddOrUpdate() that works in this manner. The following is an example of such overload:
public static void AddOrUpdate(Expression<Action> methodCall, T arg, Func cronExpression, TimeZoneInfo timeZone = null, string queue = “default”);
This way we can create a recuring job and specify an argument so that it is passed to our action when the job will be executed at its time.
RecurringJob.AddOrUpdate(x => Console.WriteLine(x), “my arg”, Cron.Minutely());
I know that there is already an overload as below:
public static void AddOrUpdate(string recurringJobId, Expression<Action> methodCall, string cronExpression, TimeZoneInfo timeZone = null, string queue = “default”);
The ‘methodCall’ will be compiled to an Action, so your action indeed has a parameter. But there’s no place in AddOrUpdate()'s arguments where you can specify the argument. What does the ‘methodCall’ really receive when it is called?