Routine execution in the background via Hangfire (ASP.NET Webforms)

Asked

Viewed 131 times

0

I am in need of doing a background run on my system. For this I found the Hangfire tool. I made the settings according to the documentation and am getting the error: Value cannot be null. Parameter name: method

Below my code:

public class Global : HttpApplication
{
    private string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
    private BackgroundJobServer _backgroundJobServer;

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        var storage = new SqlServerStorage(connectionString); // db_HangFire is the connection string for Sql Server DB used as Job Storage for HangFire for processing 
        var options = new BackgroundJobServerOptions();
        _backgroundJobServer = new BackgroundJobServer(options, storage);
        _backgroundJobServer.Start(); // start BackgroundJobServer process
        JobStorage.Current = storage; // assign the storage to Current

    }

    protected void Application_End(object sender, EventArgs e)
    {
        _backgroundJobServer.Dispose(); // Dispose the BackgroundJobServer Object
    }
}


namespace HangFireWebForms
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnEnqueue_Click(object sender, EventArgs e)
        {

            BackgroundJob.Enqueue(() => HangFireTask(this.txtMensagem.Text));
        }

        private void HangFireTask(string message)
        {
            this.lblHangFireResultTask.Text = message;
        }
    }
}
  • Where are you getting this error?

  • 1

    The error happens right when running Backgroundjob.Enqueue()

  • And where the Hangfiretask is?

  • Buddy, I’m not sure what you’re wondering. There is a Hangfirewebforms form where I put a button and click it should queue the Hangfiretask method that is declared in the same form. You can see by my code that Hangfiretask is implemented just below the click.

  • Actually this error is looking like some configuration detail besides the HangFireTask() be set to private, does not appear to have another error. You have checked if it created the tables in the given database?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.