I have asp.net core API application and this is the first time i will be using HangFire.
In .Net Core application all my methods are async. Based on SO Post it's not good idea to use wait()
while calling async method in hangfire.
Also as per the hangfire support issue in v1.6.0, async support was added. I am using version 1.6.12 but still i dont see async support.
How do i call async method from Enqueue
. Currently i am using wait()
public class MyController : Controller
{
private readonly Downloader _downlaoder;
private readonly IBackgroundJobClient _backgroungJobClient;
public MyController(Downloader downloader, IBackgroundJobClient backgroungJobClient)
{
_downlaoder = downloader;
_backgroungJobClient = backgroungJobClient;
}
[HttpPost]
public void Post([FromBody]IEnumerable<string> files)
{
_backgroungJobClient.Enqueue(() => _downloader.DownloadAsync(files).Wait());
}
}