I have a function -
public async Task DoWork(Frequency value) { // do work }
The idea here is to add this function as a recurring job to Hangfire.
Adding the job explicitly works, like this -
RecurringJob.AddOrUpdate("triggerId", () => DoWork(frequency), Cron.Daily())
However, if I want to create a function to add triggers
private void AddTrigger(string triggerId, Frequency frequency, Func<Frequency, Task> trigger)
{
RecurringJob.AddOrUpdate(triggerId, () => trigger(frequency), Cron.Daily());
}
I get an error Expression body should be of type 'MethodCallExpression'
When I debug it seems like they are the same type of objects. What am I missing here that is causing this error?
() => trigger(frequency) {Method = {System.Threading.Tasks.Task <<>m0>b__0()}} object {System.Func<System.Threading.Tasks.Task>}
() => DoWork(frequency) {Method = {System.Threading.Tasks.Task <<>m0>b__0()}} object {System.Func<System.Threading.Tasks.Task>}