title: How to fire an asynchronous task, but wait for all callbacks before returning ActionResult?
body: <p>I have an ASP.NET MVC 3 action method which accepts a <code>HttpFileCollectionBase</code> in the HTTP POST.</p>
  
  <p>In this method, i need to resize and upload the image 3 times.</p>
  
  <p>The action method currently looks like this:</p>
  
  <pre><code>public ActionResult ChangeProfilePicture()
  {
     var fileUpload = Request.Files[0];
  
     ResizeAndUpload(fileUpload.InputStream, Size.Original);
     ResizeAndUpload(fileUpload.InputStream, Size.Profile);
     ResizeAndUpload(fileUpload.InputStream, Size.Thumb);
  
     return Content("Success", "text/plain");   
  }
  </code></pre>
  
  <p>Basically this is a user profile page, where they change their profile pic. The upload happens via jQuery AJAX.</p>
  
  <p>Now, how can i fire off the three <code>ResizeAndUpload</code> calls as asynchronous tasks, but not return the action result until all three tasks have completed?</p>
  
  <p>Previously i've been using <code>Task.Factory.StartNew</code> to fire off asynchronous tasks, but that was when i didn't care about waiting for the result.</p>
  
  <p>Any ideas?</p>