I have written a simple console app that should print a message every minute. I do get the first print message saying "starting" however i do not get the message in the PrintTest()
method in my console. What is the reason for this ? By the way, this is a .net core console application.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting");
GlobalConfiguration
.Configuration
.UseSqlServerStorage(@"Server=127.0.0.1,1433; Database=HFTest; User Id=sa; Password=Password123");
RecurringJob.AddOrUpdate((() => PrintTest()), Cron.Minutely());
Console.ReadKey();
}
public static void PrintTest()
{
Console.WriteLine("Hangfire Server started. Press any key to exit...");
}
}
You need to create a
BackgroundJobServer
withusing
block and put your RecurringJob in it:Refer to https://docs.hangfire.io/en/latest/background-processing/processing-jobs-in-console-app.html