Background worker not working right
Posted
by vbNewbie
on Stack Overflow
See other posts from Stack Overflow
or by vbNewbie
Published on 2010-04-27T16:52:21Z
Indexed on
2010/04/27
16:53 UTC
Read the original article
Hit count: 376
visual-studio
|visual-basic
I have created a background worker to go and run a pretty long task that includes creating more threads which will read from a file of urls and crawl each. I tried following it through debugging and found that the background process ends prematurely for no apparent reason. Is there something wrong in the logic of my code that is causing this. I will try and paste as much as possible to make sense.
While Not myreader.EndOfData
Try
currentRow = myreader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
itemCount = itemCount + 1
searchItem = currentField
generateSearchFromFile(currentField)
processQuerySearch()
Next
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
Console.WriteLine(ex.Message.ToString)
End Try
End While
This first bit of code is the loop to input from file and this is what the background worker does. The next bit of code is where the background worker creates threads to work all the 'landingPages'. After about 10 threads are created the background worker exits this sub and skips the file input loop and exits the program.
Try
For Each landingPage As String In landingPages
pgbar.Timer1.Stop()
If VisitedPages.Contains(landingPage) Then
Continue For
Else
Dim thread = New Thread(AddressOf processQuery)
count = count + 1
thread.Name = "Worm" & count
thread.Start(landingPage)
If numThread >= 10 Then
For Each thread In ThreadList
thread.Join()
Next
numThread = 0
Continue For
Else
numThread = numThread + 1
SyncLock ThreadList
ThreadList.Add(thread)
End SyncLock
End If
End If
Next
© Stack Overflow or respective owner