title: Multi-threading with the Task library
body: <p>in ASP.NET MVC I have an Action that accepts a list of email addresses entered by the user, validates them and then sends HTML and text version of email message to each recipient. User is then redirected to the thanks page. Because it is not necessary to wait with the redirect to thanks page until all email messages are sent, I am using Task.Factory.StartNew method to start a new task that actually sends email messages and it works fine; the user is immediately redirected to the thanks page and email messages are sent on a separate thread.
  So everything works as I want to, but nevertheless I have the following questions regarding the multi-threading. I read quite a lot of posts last days, but I still do not have all the answers, here are some facts that I have extracted from these posts (note that these are my assumptions only and I write them down here, so you can comment and improve them):</p>
  <ol>
  <li><p><strong>Task library uses thread from thread pool</strong></p>
  <p>If you are using Task library, your are creating new thread by using thread from ASP.NET thread pool. That means that one thread less is available for serving other ASP.NET requests for the application. So by using task library your are not optimizing usage of ASP.NET threads by offloading tasks to some other OS thread, only user experience is better, but Task library uses another thread that could be used for serving other ASP.NET requests. So the only consequence is that the user does not need to wait.</p>
  </li>
  <li><p><strong>Manual thread</strong></p>
  <p>If you really want to use OS threads, you must start new Thread explicitly. But even if you start new OS thread, you need to have machine with multiple cores or processors to really see an improvement in application scalability.</p>
  </li>
  <li><p><strong>Background thread pool</strong></p>
  <p>Some posts talk about ASP.NET thread pool and a separate application's background thread pool which is used for background tasks. In other words, each ASP.NET application has one thread pool to serve application requests and another thread pool to serve background tasks. I do not think that's true, I think each ASP.NET application has only one thread pool and threads from this pool are used to server both: application requests and background tasks. Maybe this could be said for Windows Forms application when there's usually only one thread running (UI thread) and you must explicitly start new thread. But ASP.NET is multi-threaded in its basics.</p>
  </li>
  </ol>
  <p>Here are the questions:</p>
  <ol>
  <li><p>I have read about async MVC controllers in Programming ASP.NET MVC 2 by Dino Esposito. He writes about how async controller uses OS thread for long running task and thus ASP.NET thread that served ASP.NET request initially is now free to server other requests.</p>
  <p>Although I do not need async controller here, my questions is how can I use such OS thread in my example. Do I have to start separate thread explicitly or is this also somehow possible with Task library?</p>
  </li>
  <li><p>Even if I offload such taks to some OS thread will there be any benefit if the machine only has one processor? I think multi-core machine is necessary to really improve the scalability of the application.</p>
  </li>
  </ol>