title: Task.Factory.StartNew won't wait for task completion?
body: <p>I've found that the following code won't actually wait for the task client.SendAsync() if I use the implementation:</p>
  
  <pre><code>taskList.Add(Task.Factory.StartNew(() =&gt; new Program().Foo()));
  </code></pre>
  
  <p>If I change it from <code>Task.Factory.StartNew()</code> to just <code>new Program().Foo()</code> or <code>Task.Run(() =&gt; new Program.Foo()</code> it will correctly output some information. What are the differences between the two?</p>
  
  <pre><code>internal class Program
  {
      private async Task Foo()
      {
          while (true)
          {
              var client = new HttpClient();
              var requestMessage = new HttpRequestMessage(HttpMethod.Head, "http://www.google.com");
              HttpResponseMessage response = await client.SendAsync(requestMessage);
              Console.WriteLine(response.RequestMessage.RequestUri.ToString());
          }
      }
  
      private static void Main(string[] args)
      {
          var taskList = new List&lt;Task&gt;();
  
          // This won't output anything.
          taskList.Add(Task.Factory.StartNew(() =&gt; new Program().Foo()));
  
          // This will.
          taskList.Add(Task.Run(() =&gt; new Program().Foo()));
  
          // So does this.
          taskList.Add(new Program().Foo());
  
          Task.WaitAll(taskList.ToArray());
      }
  }
  </code></pre>
  
  <p>Based on <a href="http://blogs.msdn.com/b/pfxteam/archive/2011/10/24/10229468.aspx" rel="noreferrer">this MSDN article</a>, it seems <code>Task.Run(someAction);</code> is equivalent to <code>Task.Factory.StartNew(someAction, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);</code></p>
  
  <p>But even when I change the code to this, it won't output anything. Why?</p>
  
  <pre><code>internal class Program
  {
      private async Task Foo()
      {
          while (true)
          {
              var client = new HttpClient();
              var requestMessage = new HttpRequestMessage(HttpMethod.Head, "http://www.google.com");
              HttpResponseMessage response = await client.SendAsync(requestMessage);
              Console.WriteLine(response.RequestMessage.RequestUri.ToString());
          }
      }
  
      private static void Main(string[] args)
      {
          var taskList = new List&lt;Task&gt;();
          taskList.Add(Task.Factory.StartNew(() =&gt; new Program().Foo(), CancellationToken.None,
              TaskCreationOptions.DenyChildAttach, TaskScheduler.Default));
          //taskList.Add(Task.Run(() =&gt; new Program().Foo()));
          //taskList.Add(new Program().Foo());
          Task.WaitAll(taskList.ToArray());
      }
  }
  </code></pre>