title: Manage thread execution in a Threadpool class in C #
body: <p>I created an application that uses dynamic threads, using the following function:</p>
  
  <pre><code>foreach (DataGridViewRow row in dtConexiones.Rows)
          {
              Object ip = Convert.ToString(row.Cells["ip"].Value);
              ThreadPool.QueueUserWorkItem(new WaitCallback(setTimer), ip);
              Console.Read();
          }
  </code></pre>
  
  <p>You may notice that a number of threads are created, based on the number of records in the "ip" column, inside a Datagridview control, I mean, I have five records, so I have five threads.</p>
  
  <p>In the same way <code>ThreadPool.QueueUserWorkItem (new WaitCallback (setTimer), ip);</code>
  Creates the threads, and executes the setTimer function receiving as parameter the value ip, which is a String, to create a timer for each thread.</p>
  
  <p>This process works perfectly, the threads are created, but when the program is executed, thread 1 is executed once, then thread 2 is left running indefinitely.</p>
  
  <p>How can I manage the threads created by ThreadPool so they can be executed one by one, without running a thread x?</p>
  
  <p>In the following image of the execution you can see how the thread 192.168.1.123 is executed twice and from there, the thread 192.168.1.124 is executed indefinitely, when what I would like is for both to execute at par. Greetings and thanks for your valuable help.</p>
  
  <p><a href="https://i.stack.imgur.com/wpVMH.jpg" rel="nofollow noreferrer">enter image description here</a></p>