title: C# - How to Both Await Tasks and Assign Values to Variables
body: <p>I've been attempting to figure this out for a bit now but I can't seem to wrap my head around it. I have the following async task which calls other async tasks from my ClientFunctions object named "c".</p>
  
  <pre><code>public async Task RunAsync(Dictionary&lt;int, Robots&gt; botList)
  {
      this.botList = botList;
      Task[] tasks = new Task[botList.Count]; //5 tasks for each bot, 5 bots total in a list
  
      for (int i = 0; i &lt; botList.Count; i++)
      {
          tasks[i] = botList[i].c.StartClient();
          await tasks[i];
  
          tasks[i] = botList[i].c.setConnection();
      }
      await Task.WhenAll(tasks);
      Form1.Log("All done");
  }
  </code></pre>
  
  <p>I await after <code>StartClient()</code> because it writes data to a shared file, and <code>setConnection()</code> reads the data from that file. I do this for all 5 bots.</p>
  
  <p>The <code>StartClient()</code> function returns a Process, and I want to store that Process in each bot's class in a variable called "<strong>proc</strong>". </p>
  
  <p>How would I go about storing the result while still being able to use a task array to wait for all 5 to complete?</p>
  
  <p>Thanks.</p>