I am trying to implement cron task on a web application in ASP.Net Core 1.1.
I decided to choose the Hangfire library.
In order to check if my installation and c
So your problem is that Hangfire serializes the arguments you send to the job using NewtonSoft. When your program enqueues the job, it gets the current time, and then will call that function with that time.
Try moving the function into a method call. So instead of
RecurringJob.AddOrUpdate(() => Console.WriteLine($"{DateTime.Now}"), Cron.Minutely);
Try
RecurringJob.AddOrUpdate(() => PrintTime(), Cron.Minutely);
...
private static void PrintTime() {
Console.WriteLine($"{DateTime.Now}");
}
If my understanding of Hangfire is correct, this will only serialize the name of the method to call, but not serialize the time.