title: Why is using multiple threads not improving performance?
body: <p>So I've been trying stuff with the c# <code>WebClient</code>. I managed to make a working program (console application) with code similar to this:</p>
  
  <pre><code>static void Search(string number)
  {
      using (var client = new WebClient())
      {
          for (int a = 0; a &lt; globalvariable.lenght; a++)
          {
              string toWrite = "nothing";
              for (int b = 0; a &lt; globalvariable2.lenght; b++)
              {
                  string result = client.DownloadString(urlString);
                  //do stuff with toWrite if page is not empty
                  //change toWrite and break the b loop
              }
              Console.WriteLine(toWrite);
          }
      }
  }
  </code></pre>
  
  <p>It isn't really fast so I thought I can make it faster by using multiple threads.
  It takes 2 minutes to execute.</p>
  
  <p>So I tried making the loop a <code>Parallel.For</code> loop. It still took 2 minutes to execute. So I read stuff in here and made the following code:</p>
  
  <pre><code>static async Task AWrite(string number, int a) 
  {
      using (var client = new WebClient())
      {
          string toWrite = "nothing";
          for(int b=0; a&lt;globalvariable2.lenght; b++)
          {
              string result = await client.DownloadStringTaskAsync(uri);
              //do stuff with toWrite if page is not empty
              //change toWrite and break the b loop
          }
          Console.WriteLine(toWrite);
      }
  }
  </code></pre>
  
  <p>And then the function to call it:</p>
  
  <pre><code>private static void ASearch(string number)
  {
      var tasks = new List&lt;Task&gt;();
      for(int a=0; a&lt;gobalvariable.Length; a++)
      {
          tasks.Add(AWrite(number, a));
      }
      Task.WaitAll(tasks.ToArray());
  }
  </code></pre>
  
  <p>So I thought that multiple <code>WebClient</code> will download the strings simultaneously, apparently that doesn't happen as this also takes two minutes to execute. Why is that? By the writing in the console I know that they are not executing in order, but it still takes same amount of time. How can I actually improve performance of the first function through the use multiple threads?</p>