2

I've this method:

public class Publish
{
    public async Task NowAsync(bool isFinal)
    {
        //...
    }
}

and I want to pass it as a parameter here instead of () => Console.WriteLine():

RecurringJob.AddOrUpdate("name", () => Console.WriteLine("Hello"));

AddOrUpdate method accepts a parameter of type Expression<Action>

How can I do it? thanks.

Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76
Blendester
  • 1,583
  • 4
  • 19
  • 43

1 Answers1

4

Starting with hangfire 1.6 (which is 1.5 years old at this moment) you can pass async methods (methods that return Task) to AddOrUpdate without converting them to synchronous methods (to Action):

RecurringJob.AddOrUpdate("name", () => NowAsync(true), (string) null);
jbl
  • 15,179
  • 3
  • 34
  • 101
Evk
  • 98,527
  • 8
  • 141
  • 191