title: In self-hosted OWIN Web API, how to run code at shutdown?
body: <p>I am self-hosting a OWIN Web API using these code snippets:</p>
  
  <pre><code>class Startup
  {
      public void Configuration(IAppBuilder appBuilder)
      {
          var config = new HttpConfiguration();
          var route = config.Routes.MapHttpRoute("DefaultApi", "{controller}");
          appBuilder.UseWebApi(config);
      }
  }
  
  WebApp.Start&lt;Startup&gt;("http://localhost:8080")
  </code></pre>
  
  <p>I would like to run some code when my Web API service shuts down. I'm looking for something like <code>HttpApplication.Application_End</code>, a <code>Disposed</code> event, or a well-placed <code>override void Dispose()</code>.</p>
  
  <p>How do I run code when the Web API service shuts down?</p>