Parallel.For Loop Q?

How can I use Step in a Parallel.For loop?

For Instance, I can do this:
For i As Integer = 0 To 100 Step 10
   'Do Something
Next

But this:
Parallel.For(0, 100 Step 10, Function(i)
   'Do Something
                                         End Function)

bombs with an Overload error
LVL 25
kevp75Asked:
Who is Participating?
 
nmarunCommented:
Have a look here: http://www.lovethedot.net/2009/02/parallelfor-deeper-dive-parallel.html - tells you there's no way to give a step-size for the Parallel.For method.

Arun
0
 
wdosanjosCommented:
AFAIK, there is no way to set the Step on a Parallel.For (it is always 1).  You can work around this limitation by calculating your index as below:

Parallel.For(0, 10, Function(i)
                    Dim index As Integer = i * 10
                    'Do Something
                    End Function)

Open in new window

0
 
nmarunCommented:
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kevp75Author Commented:
Arun, i don't understand how it applies to my need
0
 
kevp75Author Commented:
hello?
0
 
kevp75Author Commented:
it doesn't say anywhere in that article that a step size cannot be used.
0
 
nmarunCommented:
The article says:

you wouldn’t be able to modify the iterator inside the loop as you can in for

Arun
0
 
kevp75Author Commented:
ah
0
 
wdosanjosCommented:
BTW, I provided the answer way before the accepted solution.
0
 
nmarunCommented:
wdosanjos, Although you did answer the question before, I think your 'AFAIK' (your first post) intimated the author that you were not sure and that there might be a way of doing this. But when I provided a documented way of telling this, the author was convinced. So I'm ok with a half-split of points on this. Sorry, this was an oversight by me, should have seen this before.

kevp75, Please split the points between wdosanjos and I.

Arun
0
 
kevp75Author Commented:
tank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.