title: How can i call an async action method using Hangfire
body: <p>I am working on an asp.net mvc5 web application, and i installed the Hangfire :-</p>
  
  <pre><code>Install-Package Hangfire
  </code></pre>
  
  <p>after that i created a startup.css class as follow:-</p>
  
  <pre><code>public class Startup
  {
     public void Configuration(IAppBuilder app)
     {
  
     }
  }
  </code></pre>
  
  <p>then inside my global.asax file i tried calling 2 action methods ; <code>Index ()</code> &amp; <code>ScanServer()</code>, as follow:-</p>
  
  <pre><code> HomeController h = new HomeController();
          protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();
              RouteConfig.RegisterRoutes(RouteTable.Routes);
  
  
              RecurringJob.AddOrUpdate(() =&gt;  h.Index(), Cron.Minutely);
          }
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code> RecurringJob.AddOrUpdate(() =&gt;  h.ScanServer(*****), Cron.Minutely);
  </code></pre>
  
  <p>now when Hangfire tried calling the Index() action method which have the following definition :-</p>
  
  <pre><code> public ActionResult Index()
  </code></pre>
  
  <p>i got this error:-</p>
  
  <blockquote>
    <p>JobStorage.Current property value has not been initialized. You must
    set it before using Hangfire Client or Server API.</p>
  </blockquote>
  
  <p>while when Hangfire tried calling the ScanServer() action method which is an async Task ,which have the following definition :-</p>
  
  <pre><code> public async Task&lt;ActionResult&gt; ScanServer(string tokenfrom)
  </code></pre>
  
  <p>i got this error:-</p>
  
  <blockquote>
    <p>Async methods are not supported. Please make them synchronous before
    using them in background.</p>
  </blockquote>
  
  <p>so can anyone advice how to fix these 2 issues ?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>i wrote the following inside the Startup class:-</p>
  
  <pre><code>using Hangfire;
  using Microsoft.Owin;
  using Owin;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using ScanningFinal;
  [assembly: OwinStartup(typeof(Startup))]
  namespace ScanningFinal
  {
  
      public class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              GlobalConfiguration.Configuration
             .UseSqlServerStorage("scanservice");
          }
      }
  }
  </code></pre>
  
  <p>&amp; here is the connection string:-</p>
  
  <pre><code> &lt;add name="scanservice"    connectionString="data source=localhost;initial catalog=ScanningService;integrated security=True" providerName="System.Data.SqlClient"/&gt;
  </code></pre>
  
  <p>but i am still getting this error :-</p>
  
  <blockquote>
    <p>JobStorage.Current property value has not been initialized. You must
    set it before using Hangfire Client or Server API.</p>
  </blockquote>