I have implemented Hangfire in .NET Console Application and It’s working fine. After submitting Tasks(In my case downloading documents) to Hangfire I need to update the status of the Task(Document download status) in the Database, for this, I have the “UpdateDocumentStatus();” method but it never executed (Executing when entering something in the Console cmd window) as I have Console.ReadKey(); in the program. If I remove Console.ReadKey(); Hangfire not working.
Please suggest me alternative to Console.ReadKey(); for Hangfire to execute my “UpdateDocumentStatus();”
using System;
using Hangfire;
using Hangfire.MemoryStorage;
namespace HangFire
{
class Program
{
static void Main(string[] args)
{
GlobalConfiguration.Configuration.UseMemoryStorage();
BackgroundJob.Enqueue(() => DownloadDocument());
using (var server = new BackgroundJobServer())
{
Console.ReadKey(); //Need alternative to this line to execute below code
}
UpdateDocumentStatus();
}
public static void DownloadDocument()
{
Console.WriteLine("Downloading documents...");
}
public static void UpdateDocumentStatus()
{
Console.WriteLine("Update status...");
}
}
}