I have the following sub that works just fine. This code gets a list of 300+ folders from the P:\ Drive and a thread then will get a list of all the files in each folder and sort out the file with the latest date. This works fine, except the server where P:\ is at is hung up for ~ 2 - 3 minutes processing each request from each thread.
I would like to only do say 20 - 40 threads a at time, but don't really know how to know when a thread is finished so I can add another to the pile.
What I would like to do is use this function and have a loop inside that would only have 25 threads going at one time? Or other suggestions would be welcomed.
Public Sub GetDirs()
Dim dir As String
Dim i As Integer = 1
Dim j As Integer
Dim dirs() As String = Directory.GetDirectories("P:\")
ProgressBar1.Maximum = dirs.Length
Dim tColl As Threading.ThreadPool
For Each dir In dirs
Dim objThread As Threading.Thread
Dim objProcess As New MyThreadClass(New UpdateTreeviewHandler(AddressOf UpdateTreeview_Callback))
objThread = New Threading.Thread(AddressOf objProcess.Process)
objProcess.sFolder = dir
objThread.Name = dir
i += 1
ProgressBar1.Value = ProgressBar1.Value + 1
MsgBox("Finished getting Information")