title: How to configure a maximum number of threads in a Parallel.For
body: <p>This is the example microsoft presents for the parallel for, and I'd like to know how configure a maximum number of threads for this code.</p>
  
  <pre><code>     // A basic matrix multiplication.
       // Parallelize the outer loop to partition the source array by rows.
       System.Threading.Tasks.Parallel.For(0, matARows, i =&gt;
       {
          for (int j = 0; j &lt; matBCols; j++)
          {
             // Use a temporary to improve parallel performance.
             double temp = 0;
             for (int k = 0; k &lt; matACols; k++)
             {
                temp += matA[i, k] * matB[k, j];
             }
             result[i, j] = temp;
          }
       }); // Parallel.For
  </code></pre>