title: Prevent IIS from killing a Task before it ends
body: <p>I'm building a Logging library that stores everything on an Azure table. Writing to that table obviously takes a lot of time (never more than 1 sec, but it's still too much to make the user wait), so Log method returns a LogResult instance, here's the class</p>
  
  <pre><code>public class LogResult
  {
      public string Id { get; set; }
      public Task LoggingTask { get; set; }
  
      public LogResult(string id, Task task)
      {
          Id = id;
          LoggingTask = task;
      }
  }
  </code></pre>
  
  <p>And here is how the Log method finishes</p>
  
  <pre><code>return new LogResult(id, Task.Factory.StartNew(() =&gt; 
      DoLogInAzure(account, id, exception, request))
  );
  </code></pre>
  
  <p>To give the caller the option of waiting for it to complete (if it's a console app, for instance). The issue I'm facing is that IIS <em>shouldn't</em> wait for it before returning the user the response... and if I don't wait for it, IIS doesn't <em>always</em> execute the task. The idea is to show the user a message "... If you contact us, be sure to mention your issue number, XXX" and don't make him wait until the log entry has been written.</p>
  
  <p>Is there any way to force IIS to wait until the task finishes, even after it returned the response? I'm thinking I may need to code a Windows Service that takes the request asynchronously, but it looks like a lot of work just to add a log entry... specially if I can force IIS to wait for it.</p>
  
  <p>Thanks for any ideas!</p>