title: Wait few webresponses at the same time
body: <p>I want wait all responses one time.</p>
  
  <pre><code>for (int i = 0; i &lt; N; i++)
  {
      request = (HttpWebRequest)WebRequest.Create(url[i]);
      // init other request headers...
  
      // get response
      using (HttpWebResponse response = await Web.GetHttpWebResponseAsync(request))
      {
          string strResponse = Web.ConvertHttpWebResponseToString(response, System.Text.Encoding.GetEncoding("utf-8"));
      }
  }
  </code></pre>
  
  <p>It work but second step of cycle wait while data for i = 0 was loaded (long time). I want all N requestes waiting in one time. I try this:</p>
  
  <pre><code>List&lt;Task&lt;HttpWebResponse&gt;&gt; ts = new List&lt;Task&lt;HttpWebResponse&gt;&gt;();
  for (int i = 0; i &lt; N; i++)
  {
      request = (HttpWebRequest)WebRequest.Create(url[i]);
      // init other request headers...
  
      // save task in list
      ts.Add(Web.GetHttpWebResponseAsync(request));
  }
  
  Task.WaitAll(ts.ToArray());
  
  for (int i = 0; i &lt; N; i++)
  {
      string strResponse = Web.ConvertHttpWebResponseToString(ts[i].Result, System.Text.Encoding.GetEncoding("utf-8")); // &lt;== but I get error access to disposed stream.
  }
  </code></pre>
  
  <p>How I can wait all responses one time?<br/>
  Thx for your help.</p>
  
  <pre><code>public static string ConvertHttpWebResponseToString(HttpWebResponse response, Encoding encoding)
  {
      string data = "";
      System.IO.Stream responseStream = response.GetResponseStream(); // &lt;-- error on this
      using (System.IO.StreamReader reader = new StreamReader(responseStream, encoding))
      {
          data += reader.ReadToEnd();
      }
      responseStream.Close();
      return data;
  }
  </code></pre>
  
  <p><strong>EDIT</strong><br/>
  I replace response in own function and it works:</p>
  
  <pre><code>public static async Task&lt;string&gt; GetRespStr(HttpWebRequest request)
  {
      string strResponse = null;
      using (HttpWebResponse response = await Web.GetHttpWebResponseAsync(request))
      {
          strResponse = Web.ConvertHttpWebResponseToString(response, System.Text.Encoding.GetEncoding("utf-8"));
      }
      return strResponse;
  }
  
  void main()
  {
      for (int k = 0; k &lt; cnt; k++)
      {
          request = (HttpWebRequest)WebRequest.Create(href[k]);
          tasks.Add(GetRespStr(request));
      }
  
      Task.WaitAll(tasks.ToArray());
  
      for (int k = 0; k &lt; cnt; k++)
      {
          result.Add(tasks[k].Result);
      }
  }
  </code></pre>
  
  <p>Question solved for me, thx.</p>