title: C# - how to do multiple web requests at the same time
body: <p>I wrote a code to check urls, however, ir works really slow.. I want to try to make it work on few urls at the same time, for example 10 urls or at least make it as fast as possible.</p>
  
  <p>my Code:</p>
  
  <pre><code>Parallel.ForEach(urls, new ParallelOptions {
    MaxDegreeOfParallelism = 10
  }, s =&gt; {
    try {
      using(HttpRequest httpRequest = new HttpRequest()) {
        httpRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0";
        httpRequest.Cookies = new CookieDictionary(false);
        httpRequest.ConnectTimeout = 10000;
        httpRequest.ReadWriteTimeout = 10000;
        httpRequest.KeepAlive = true;
        httpRequest.IgnoreProtocolErrors = true;
        string check = httpRequest.Get(s + "'", null).ToString();
        if (errors.Any(new Func &lt; string, bool &gt; (check.Contains))) {
          Valid.Add(s);
          Console.WriteLine(s);
          File.WriteAllLines(Environment.CurrentDirectory + "/Good.txt", Valid);
        }
      }
    } catch {
  
    }
  });
  </code></pre>