Public Sub DoWork(ByVal objItem As Object) static _sem as Semaphore = new Semaphore(5,10) '// Capacity of 10 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 ' Queue a task 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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)