title: How to make a BackgroundWorker survive an app pool recycle
body: <p>In a .NET Core api application a BackgroundService is configured thusly:</p>
  <pre><code>services.AddHostedService&lt;AuthorizationMessageConsumerService&gt;();
  </code></pre>
  <p>where</p>
  <pre><code>public class AuthorizationMessageConsumerService : BackgroundService
  </code></pre>
  <p>The app pool servicing this application is configured to never go Idle and Start Mode is AlwaysRunning. I must of automatically assumed AlwaysRunning meant create a new request worker thread and the hosted <code>BackgroundService</code> would automatically be invoked via the api's Startup class, however, that is not the case. The iis worker thread starts but the application's startup only runs after a ping to it's health check (an incoming http request).</p>
  <p>Is there a way to not make a ping a requirement to start the service after a deployment which invokes an app pool recycle or is there some code or configuration that I may have missed?</p>
  <p>Currently, the app does not go idle and it's app pool does not recycle unless a deployment occurs which makes sense. I would expect to see a startup message after #4 below, but it only happens after the first ping.</p>
  <p><strong>During Deployment</strong></p>
  <ol>
  <li>1/28/2022 9:25:15 AM - Running job: Release</li>
  <li>1/28/2022 9:25:28 AM - Application 'C:&lt;path to app&gt;' was recycled after detecting app_offline.htm.</li>
  <li>1/28/2022 9:25:29 AM - Application 'MACHINE/WEBROOT/APPHOST//' has shutdown.</li>
  <li>1/28/2022 9:25:33 AM - Job Release completed with result: Succeeded</li>
  </ol>
  <p><strong>After /Health ping</strong></p>
  <ol>
  <li>Application 'C:&lt;path to app&gt;\Authorization' started successfully.</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/yMHp8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yMHp8.png" alt="IIS Configuration" /></a></p>
  <p><a href="https://i.stack.imgur.com/A5d5B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A5d5B.png" alt="enter image description here" /></a></p>