title: c# build a list of tasks before executing
body: <p>i'm trying to build a list of tasks before executing them.  here's some example code:</p>
  
  <pre><code>    public string Returnastring(string b)
      {
          return b;
      }
  
      public string Returnanotherstring(string a)
      {
          return a;
      }
  
  
      private void btnT_Click(object sender, EventArgs e)
      {
          bool cont = true;
  
          var Returnastringtask = Task.Factory.StartNew(() =&gt; Returnastring("hi"));
          var Returnanotherstringtask = Task.Factory.StartNew(() =&gt; Returnanotherstring("bye"));
  
          if (cont)
          {
              Task.WaitAll(new Task[] { Returnastringtask });
          }
          else
          {
              Task.WaitAll(new Task[] { Returnanotherstringtask });
          }
  </code></pre>
  
  <p>i know this code doesn't behave how i expect it as both tasks run.  i want to basically create the tasks initially and then execute one or the other based on the bool.  i don't want to create the tasks inside the true or false conditions as i want to avoid code copying.  by  this i mean if cont is true i might want to run tasks 1,2,3,4 but if cont is false i might want to run tasks 2,3,7,8.</p>