title: Dynamically run more than one thread in c#
body: <p>I have a program where I need to run a number of threads at the same time</p>
  
  <pre><code>int defaultMaxworkerThreads = 0;
  int defaultmaxIOThreads = 0;
  ThreadPool.GetMaxThreads(out defaultMaxworkerThreads, out defaultmaxIOThreads);
  ThreadPool.SetMaxThreads(defaultMaxworkerThreads, defaultmaxIOThreads);
  
  List&lt;Data1&gt; Data1 = PasswordFileHandler.ReadPasswordFile("Data1.txt");
  List&lt;Data1&gt; Data2 = PasswordFileHandler.ReadPasswordFile("Data2.txt");
  while (Data1.Count &gt;= 0)
  {
  
      List&lt;String&gt; Data1Subset = (from sub in Data1 select sub).Take(NumberOfWordPrThead).ToList();
     Data1 = _Data1.Except(Data1Subset ).ToList();
     _NumberOfTheadsRunning++;
     ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadCompleted), new TaskInfo(Data1Subset , Data2 ));
      //Start theads based on how many we like to start
  }
  </code></pre>
  
  <p>How can I run more than 1 thread at a time? I would like to decide the number of threads at run-time, based on the number of cores and a config setting, but my code only seems to always run one one thread. </p>
  
  <p>How should I change it to run on more than one thread?</p>