Hey guys,

So, i have a list that has things that needs to be looped. This list can be up to 500k items.


I would like to add a multithreading option with a variable. This is not an issue, as I know how to make multiple bgw's (Code below)

Code:
               i = spin_NumOfThreads.Value
        Dim bgwrks(i) As System.ComponentModel.BackgroundWorker

 For Each bgworker As System.ComponentModel.BackgroundWorker In bgwrks
            bgworker = New System.ComponentModel.BackgroundWorker
            AddHandler bgworker.DoWork, AddressOf myDoWork
            AddHandler bgworker.ProgressChanged, AddressOf reportprogress
            bgworker.WorkerReportsProgress = True
            bgworker.RunWorkerAsync()
        Next
so in that code, it'll make the number of threads based off of my spineditor.

Now, ideally i'd like it to go through a list, each thread does its thing.

Now, a simple dowork would just allow it to do 1.

i would ideally like it to stay @ X threads until the list is done, so how would I basically go about remaking a thread once it finishes to continue?


So, lets say I have 50 items in a list, i set the number of threads to 5.

The first 5 would do the first 5 items, when the 1st one finishes, it works on item 6, then the next would do 7, etc. and it'd keep remaking until 50 is done.


I'm pretty stuck on the logic of how to go about doing this, and would appreciate some insight from you guys. Thanks!