title: How Define Counter Inside Parallel.Foreach And Stop That Loop In A Specific Number
body: <p>How Can I Define Counter Inside Parallel.Foreach And <strong>Stop That Loot In A Specific Number</strong>?<br>
  I asked this Question because that counter inside Parallel.ForEach does not work in a regular action.<br>
  please see this little example :  </p>
  
  <pre><code>static void Main(string[] args)
  {
      int Count_Step = -1;
      string[] lines = new string[] 
      { 
          "0",
          "1",
          "2",
          "3",
          "4",
          "5",
          "6",
          "7",
          "8",
          "9",
          "10",
          "11",
          "12",
          "13",
          "14",
          "15",
          "16",
          "17",
          "18",
          "19"
      };
  
      List&lt;string&gt; list_lines = new List&lt;string&gt;(lines);
  
      ParallelOptions parallelOptions = new ParallelOptions();
      parallelOptions.MaxDegreeOfParallelism = 3;
  
      Parallel.ForEach(list_lines, parallelOptions, (line, state, index) =&gt;
      {
          if (Count_Step == 10)
              state.Stop();
          Count_Step++;
          Console.WriteLine(index + " : " + line + " : " + Count_Step);
          //Thread.Sleep(5000);
      });
  
      Console.ReadLine();
  }
  </code></pre>
  
  <p>i want 10 lines in output, not more!<br>
  how can i do that?</p>
  
  <p>thanks in advance</p>