I am trying to schedule a Hangfire job like this:
In my Startup.cs, I have this:
RecurringJob.AddOrUpdate(() => sb.AddSendItems(), "0 7 * * 5");
And the method is async:
public async void AddSendItems()
{
//...add items to database and 3rd party scheduler
}
It builds fine, but when I try to run it, I get this:
System.NotSupportedException
Message=Async void methods are not supported. Use async Task instead.
Source=Hangfire.Core
StackTrace:
at Hangfire.Common.Job.Validate(Type type, String typeParameterName, MethodInfo method, String methodParameterName, Int32 argumentCount, String argumentParameterName)
I checked the Hangfire documentation here, and they do support async:
https://docs.hangfire.io/en/latest/background-methods/index.html?highlight=asynchronous
Has anyone had this issue?
Thanks!
CodePudding user response:
As the message suggests. "Async void methods are not supported. Use async Task instead."
public async Task AddSendItems()
{
//...add items to database and 3rd party scheduler
}