title: Passing a method to another method for Hangfire Scheduler instead of using a hardcoded method name
body: <p>I am using Hangfire and trying to just schedule a simple job. It works if I hardcode the name of the method to be triggered at the specified time, but I would like something more generic, i.e. to pass any method into this code and let Hangfire execute it on schedule. </p>
  
  <p>Here's one of the ways I tried to do it. </p>
  
  <pre><code>public static void ScheduleSingleRun(Activity parametersStorage, Action&lt;Activity, int&gt; scheduledFunction, int secondsDelay)
  {
      TimeSpan offset = new TimeSpan(0, 0, secondsDelay);
      try
      {
          BackgroundJob.Schedule(() =&gt; 
              scheduledFunction(parametersStorage, secondsDelay), offset);
          return new HangfireSchedulerResponse("Scheduled successfully.", 0);          
          ... 
  </code></pre>
  
  <p>And here is how I call this function: </p>
  
  <pre><code>HangfireScheduler.ScheduleSingleRun(parameters, TestMethod, 15);
  </code></pre>
  
  <p>Where TestMethod is the name of a method in the same class. </p>
  
  <p>This code compiles, but causes this error when running:</p>
  
  <pre><code>Expression body should be of type `MethodCallExpression`"
  </code></pre>
  
  <p>I tried Action, Func&lt;>, Delegate - nothing worked. Only specifying the explicit method name works: </p>
  
  <pre><code>BackgroundJob.Schedule(() =&gt; TestClass.TestMethod(parametersStorage, secondsDelay)
  </code></pre>
  
  <p>What am I doing wrong - is there a way to just pass a method name/reference to Hangfire instead of hardcoding it?</p>