title: Correct way to start a BackgroundService in ASP.NET Core
body: <p>I have implemented a BackgroundService in an ASP.NET Core 2.1 application:</p>
  
  <pre><code>public class MyBackgroundService : BackgroundService
  {
      protected override Task ExecuteAsync(CancellationToken stoppingToken)
      {
          while (true)
          {
              await DoSomethingAsync();
              await Task.Delay(10 * 1000);
          }
          return Task.CompletedTask;
      }
  }
  </code></pre>
  
  <p>I have registered it in my <code>ConfigureServices()</code> method:</p>
  
  <pre><code>services.AddSingleton&lt;MyBackgroundService&gt;();
  </code></pre>
  
  <p>I am currently (reluctantly) starting it by calling (and not awaiting) the <code>StartAsync()</code> method from within the <code>Configure()</code> method:</p>
  
  <pre><code>app.ApplicationServices.GetService&lt;SummaryCache&gt;().StartAsync(new CancellationToken());
  </code></pre>
  
  <p>What is the best practice method for starting the long running service?</p>