How to synchronously call async method from quartz schedule job
Quartz.NET 3.0 supports async/await out of the box. So you can (and must) now declare Execute method as Task returning and you can use async/await.
public async Task Execute(IJobExecutionContext context)
{
var result = await _repo.GetResult();
}
If you have to do it - then yes you can do that, but it will block the calling thread until the asynchronous operation is complete.
Task.Result will wrap any exception into an AggregateException.
So you should probably put your httpclient call in a try catch.
try
{
var result = _repo.GetResult().Result;
}
catch (AggregateException ae)
{
// handle exception
}
Also, it seems they are working on an AsyncJob.