title: Multihreading a with parallels and degrees on a "For" statement
body: <p>I recently learned this bit of code the other day...</p>
  
  <pre><code>    Directory.GetFiles(fileLoc).AsParallel.WithDegreeOfParallelism(3).ForAll(Sub(path) theWorker(path))
  </code></pre>
  
  <p>and it has drastically improved a few of my programs and it has me wondering if this could also be used on nested for statements?</p>
  
  <pre><code>        For x As Integer = 0 To 99
              For y As Integer = 0 To 99
                  For z As Integer = 0 To 99
                     dowork(x, y, z)
                  Next
              Next
          Next
  </code></pre>
  
  <p>would it be possible to do something like this?</p>
  
  <pre><code>For x As Integer = 0 To 99
          For y As Integer = 0 To 99
              Parallel.For(0,99,Sub(z) dowork(x,y,z).WithDegreeOfParallelism(3)
          Next
    Next
  </code></pre>
  
  <p>or would I have to do something like this to actually make it work?</p>
  
  <pre><code>    Dim thelist As New List(Of String)
  
      For x As Integer = 0 To 99
          thelist.Add(x)
      Next
  
  
      For x As Integer = 1 To 99
          For y As Integer = 0 To 99
              thelist.AsParallel.WithDegreeOfParallelism(3).ForAll(Sub(z) dowork(x,y,z))
          Next
      Next
  </code></pre>
  
  <p>As a side question, does the degrees of parallelism correspond to the number of cores dedicated to the task? If I had a 24 core server, could I essentially set the DOP to 12 and use half the CPU power to run these processes? </p>
  
  <p>If someone could teach/explain this to me it would be greatly appreciated : )</p>
  
  <p>Thanks -Z</p>