My Form1
freeze when using too many proxy threads after like 20sec it unfreeze but sometimes it freeze and I have to stop the solution.
My application use proxies and go to google and scrape images, keywords or emails ....so I have 4 options to scrape all are Public sub because I don't know how to do it other way.
What I try to do is Task Async
method which could help not freeze even if I lunch 300 threads.
My code:
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
Try
If chkManualProxies.Checked = True Then
If lstProxies.Items.Count < 0 Then
MessageBox.Show("Please upload manual proxies OR uncheck 'Manual proxies'")
stop_process2()
Return
End If
disableOnStart()
Else
btnScrapeStart()
disableOnStart()
End If
If chk_refresh_proxies.Checked Then
countdown = CInt(num_refresh.Value)
timer_countdown.Enabled = True
Me.Timer1.Interval = CInt(Me.num_refresh.Value) * 1000
Me.Timer1.Enabled = True
disableOnStart()
End If
Timer1.Enabled = True
' scrape_on_Start()
If rb_http.Checked Then _proxyType = 1
If Me.rb_socks4.Checked Then _proxyType = 2
If Me.rb_socks5.Checked Then _proxyType = 3
_proxies.Clear()
For Each item As ListViewItem In lstProxies.Items
_proxies.Add(item.SubItems(0).Text + ":" + item.SubItems(1).Text)
Next
Dim num As Integer
num = txtThreads.Value
ThreadPool.SetMinThreads(num, num)
_Count = 0
_proxycount = lblProxies.Text.Count.ToString
_runningThreads.Clear()
Try
Dim i As Integer
For i = 0 To num - 1
If rb1.Checked = True Then
ComboBox1N.Enabled = True
Select Case ComboBox1N.SelectedIndex
Case 0
Try
Dim t1 As Thread = New Thread(New ThreadStart(AddressOf TaskSub1))
t1.Priority = Threading.ThreadPriority.Normal
_runningThreads.Add(t1)
t1.Start()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Case 1
Try
Dim t2 As Thread = New Thread(New ThreadStart(AddressOf TaskSub2))
t2.Priority = Threading.ThreadPriority.Normal
_runningThreads.Add(t2)
t2.Start()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Select
Else
ComboBox1N.Enabled = True
Select Case ComboBox1N.SelectedIndex
Try
getInfo()
Dim t3 As Thread = New Thread(New ThreadStart(AddressOf TaskSub3))
t3.Priority = Threading.ThreadPriority.Normal
_runningThreads.Add(t3)
t3.Start()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Case 3
Try
getInfo()
Dim t4 As Thread = New Thread(New ThreadStart(AddressOf TaskSub4))
t4.Priority = Threading.ThreadPriority.Normal
_runningThreads.Add(t4)
t4.Start()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Select
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Thanks for any suggestion I know my code need to many changes but I would like to know what should I start to change as first and what is wrong coding, sorry I learned myself from Lynda. com and youtube.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…