title: C# Threading with Selenium
body: <p>I'm developing a C# application that opens browser and executes different tests on the same webpage. It works perfectly single-threaded, but right now I'm trying to implement multi-threading into the application, and I'm running into some issues. First, it start normally, I have a thread delay, so each thread will only open after 20 seconds, so there are no resource leaks, everything works fine until a point where I get the &quot;Unable to connect to the remote server&quot;. The server did not ran out of resources, since I'm keeping a close eye at it, I just think there are some issues with my code.</p>
  <p>This how I start the threads:</p>
  <pre><code>    for (int i = 0; i &lt; nthreads; i++)
      {
          Thread thread = new Thread(() =&gt; Bot.StartBot(conf))
          {
              IsBackground = true
          };
          thread.Start();
          System.Threading.Thread.Sleep(conf.thread_delay * 1000);
      }
  </code></pre>
  <p>and this is how I start the browser:</p>
  <pre><code>public static IWebDriver CreateBrowser(String string_proxy)
  {
  
      try
      {
  
          var cService = ChromeDriverService.CreateDefaultService();
          cService.HideCommandPromptWindow = true;
  
          var options = new ChromeOptions();
          options.AddArgument(&quot;--proxy-server=&quot; + string_proxy);
          options.AddArgument(&quot;--silent&quot;);
          options.AddArgument(&quot;--log-level=3&quot;);
          options.AddArgument(&quot;--lang=en&quot;);
          options.AddArgument(&quot;--disable-logging&quot;);
          options.AddArgument(&quot;--no-sandbox&quot;);
          options.AddArgument(&quot;--disable-infobars&quot;);
          options.AddArgument(&quot;--ignore-certificate-errors&quot;);
          options.AddArgument(&quot;--disable-dev-shm-usage&quot;);
          options.AddUserProfilePreference(&quot;profile.default_content_setting_values.images&quot;, 2);
  
  
          return new ChromeDriver(cService, options);
      }
      catch (Exception e)
      {
          try { File.AppendAllText(&quot;errors.txt&quot;, e.ToString() + Environment.NewLine + Environment.NewLine); } catch { }
          Console.WriteLine(e);
          System.Threading.Thread.Sleep(2000);
          return CreateBrowser(string_proxy);
      }
  }
  </code></pre>
  <p>I cannot find any information or guides on how to run multiple threads efficiently with selenium on C#.</p>
  <p>Thank you.</p>