i have this code which i run with queued 10,000, even when a max of 50 is set but the threadpool counts goes to high.
can anyone help me fish out the fault
Public Sub DoWork(ByVal objItem As Object)
Dim objUrl as String = DirectCast(objItem, string)
Try
If objUrl Is Nothing Then
exit sub
End If
Dim URL as New Uri(objUrl)
AddItem(URL.AbsoluteUri,gethtml(URL))
Catch ex As Exception
debug.Print("Error " & ex.StackTrace )
End Try
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
btnStart.Enabled =False
ThreadPool.SetMaxThreads(50, 50)
System.Threading.Thread.Sleep(1000)
listView1.Items.Clear
For Each sItem As String In txturls.Lines
if sItem.Trim <>string.empty
If sItem.Contains("http://")=False Then
sItem="http://" & sItem
End If
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf DoWork), sItem)
TotalItems+=1
tsslTotal.Text =String.Format ("Total Tasks: {0}",TotalItems)
end if
Next
End Sub
thanks
EDIT
for those who asked,
GetHtml gets the web page source from the Internet
AddItem adds the result if the GetHtml to Listview
thanks again for looking
EDIT
i use a this code to check the number of runing threads each second
Sub Timer1Tick(sender As Object, e As EventArgs)
tsslthreads.Text=string.Format ("Threads: {0}", Process.GetCurrentProcess().Threads.Count)
End Sub
thanks
Just wrote a small demo project. Try this code to check for available Threads and you will see, that there are only 50 threads RUNNING. compare: Your code will queue 10000 threads
My code is in c# and I had a timer added for showing the number of threads ..
hth