Hi Guys. One slight problem here
OK - I have a class that wraps your worker thread and logic to pass over a list of arrays, e.g.
Then to start the workers, I have a list of dummy URLs and create the worker instances, e.g
My problem is: This code creates 15 threads (one thread-one url) taking care of first 15 urls in testUrls. How do I make these threads start again from url 16 and so on until they finish the entire testUrls list (100 items or urls in this case)?
Thanks
OK - I have a class that wraps your worker thread and logic to pass over a list of arrays, e.g.
VB.NET:
Public Class ExtractWorker
' Private
Private mUrls As List(Of String)
Private mWorkerId As String
Private mWorkerThread As Threading.Thread
Public Sub New(ByVal urlsToProcess As List(Of String), ByVal workerId As String)
' Set properties
mUrls = urlsToProcess
mWorkerId = workerId
End Sub
Public Sub StartProcessing()
' Creates a new thread to start the internal processing
mWorkerThread = New Threading.Thread(AddressOf ProcessArray)
mWorkerThread.Name = "Worker " & mWorkerId
mWorkerThread.Start()
End Sub
Private Sub ProcessArray()
' Runs through the array processing each Url
For Each url As String In mUrls
' Output
Debug.WriteLine("Worker: " & mWorkerId & " processing url: " & url)
' Do your extraction code here
' Use thread.sleep to emulate processing
Threading.Thread.Sleep(5)
Next
End Sub
End Class
Then to start the workers, I have a list of dummy URLs and create the worker instances, e.g
VB.NET:
Dim testUrls As New List(Of String)
For n As Integer = 1 To 100
testUrls.Add("www.mysite.com/" & n.ToString)
Next
Dim threadsNo as Integer=15
Dim workers As New List(Of ExtractWorker)
For n As Integer = 0 To threadsNo
Dim ew As New ExtractWorker(testUrls.GetRange(n, testUrls.count / threadsNo), n.ToString())
workers.Add(ew)
ew.StartProcessing()
Next
My problem is: This code creates 15 threads (one thread-one url) taking care of first 15 urls in testUrls. How do I make these threads start again from url 16 and so on until they finish the entire testUrls list (100 items or urls in this case)?
Thanks