Base solution for your next web application
Open Closed

Hangfire Exception: Async void methods are not supported #4090


User avatar
0
ajayak created

I switched to Hangfire for BackgroundJob. On enqueuing a background job, I get this error

Async void methods are not supported. Use async Task instead.

Here is the code:

public override async void Execute(long userId)
        {
            await DeleteWebhooks(userId);
        }

It works fine with default BackgroundJob manager

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

1 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Related issue: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2366

    Meanwhile, run it synchronously with AsyncHelper:

    public override void Execute(long userId)
    {
        AsyncHelper.RunSync(() => DeleteWebhooks(userId));
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)