I have inherited some code below that works fine, the only problem is, I want to be able to limit the number of threads that run at any one time, at the moment I have around 8-10 jobs that run in parallel, I want to limit the number of threads to maybe 3 or 4 at any time, is this possible with the code below without too many changes?
Public Sub threading_Example()
Dim threadList As New List(Of Thread)
For n = 0 To numJobs 'about 8-10 normally
Dim new_job As New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf do_Job))
Dim job As New Job
'job.stuff = stuff
newJob.Start(job)
threadList.Add(new_job)
Next
For Each t As Thread In threadList
t.Join()
Next
End Sub
Public Sub do_Job(ByVal job As Object)
'do task
End Sub
Try to use Semaphore for example: