I just discovered that with HangFire you can have background jobs running in your .Net application but when I was testing its functionalities, I realized that the time in the method I added to a 1 minute RecurringJob does not change even though the method was triggered multiple times:
Method:
private static string GetTime()
{
return DateTime.Now.ToLongTimeString();
}
RecurringJob statement:
RecurringJob.AddOrUpdate("time", () => Console.WriteLine("Hello Hangfire! " + GetTime()), "*/1 * * * *");
My question:
Is it possible to display time updates as RecurringJob calls the method above?
the string you pass to console.writeline is being serilized and that's why it gets the time when it the anonymous method is added, bug or not? well i guess it depends on what you expect from it to do. it is explained in the documentation Hangfire Passing arguments
try using a method like this instead
private static void HelloWorldTime()
{
Console.Writeline( "hello world! : " + DateTime.Now.ToLongTimeString() );
}
RecurringJob.AddOrUpdate("time", HelloWorldTime() , "*/1 * * * *");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With