Loop calling BackgroundJob inside BackgroundJob

Hi everyone,

I just started using Hangfire and I am solving some problems.

In our code we have someting like:

    public void Run()
    {
        BackgroundJob.Enqueue(() =>
            Check()
        );
    }

    public void Check()
    {
        for (int i = 0; i < 10; i++)
        {
            BackgroundJob.Enqueue(() =>
                SendEmail()
            );
        }
    }

But everytime I try to do this kind of recursive call, something goes wrong. Or I get a endless loop, or I get a error like “Self referencing loop detected for property ‘ApplicationInstance’ with type ‘ASP.global_asax’. Path ‘RequestContext.HttpContext.ApplicationInstance.Context’.” thats just don’t make sense. If I remove BackgroundJob.Enqueue from SendEmail call, it works fine.