1

I have this sequential loop in vb.net.

For i As Integer = 0 To 615 Step 15
    DownloadSingleFile(i)
Next

The "Step 15" part in the loop is important. I'm unable to figure out a parallel substitute for this code.

I tried the below code, but it is missing the "Step 15" part.

Parallel.For(0, 615, Sub(i)
                 DownloadSingleFile(i)
                     End Sub)

Please help.

MoizNgp
  • 283
  • 1
  • 4
  • 17
  • possible duplicate of [Parallelizing a for loop with stepping in .net 4.5](http://stackoverflow.com/questions/13593342/parallelizing-a-for-loop-with-stepping-in-net-4-5) –  Sep 24 '14 at 15:59

1 Answers1

4

This should do the same:

42 (exclusive) = ((615 / 15) + 1)

Parallel.For(0, 42, Sub(i)
      DownloadSingleFile(i * 15)
 End Sub)
Bjørn-Roger Kringsjå
  • 9,849
  • 6
  • 36
  • 64
Allan S. Hansen
  • 4,013
  • 23
  • 25