Click here to Skip to main content
14,388,768 members
Rate this:
Please Sign up or sign in to vote.
See more:
This is my first attempt at using Parallel fors. I am still trying to grasp the concept, however, I keep getting errors.

Here is what I have:

Imports System
Imports System.IO
Imports System.Threading
Imports System.Threading.Tasks
Imports Parallel_class
Public Class Class1

    Dim processorcount As New ParallelOptions


    Public Sub Parallel_processing()

'this is where all the process will happen
       

    End Sub

    Public Sub TestMethod1()

        processorcount.MaxDegreeOfParallelism = Environment.ProcessorCount

        'Parallel.ForEach(0, processorcount, AddressOf Parallel_processing)

end sub


I am trying to pass a sub through this routine. I just don't know exactly what to do or which way to go.

What I have tried:

I have tried to switch between for and foreach, and then I tried to switch variables but nothing I tried to seemed to work.
Posted
Updated 31-Jul-19 7:57am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Start by working with a source: Parallel.ForEach needs a collection to iterate over, just as ForEach does. What you are trying to do is treat an integer as a collection, and that won't work!
Start here: Write a simple parallel program using Parallel.ForEach | Microsoft Docs[^] - it runs you through the process.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100