I was just trying to program a multi threading proxy checker it all work perfect with list box but at last when it finish checking it just crash the application due to multi thread i have try ed lot but didn't get any success can any one help me this my code thanx.
#Region "check proxy"
Const Tc As Integer = 1
Private _ThreadCount As Integer = Tc
Public Property ThreadCount() As Integer
Get
Return _ThreadCount
End Get
Set(ByVal value As Integer)
_ThreadCount = value
End Set
End Property
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
ThreadCount = NumericUpDown1.Value
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Label17.Text = "started"
ListBox2.SelectedIndex = 0
If ListBox2.Items.Count = Nothing Then
MsgBox("Please load Proxy To check.")
Else
Try
BackgroundWorker2.RunWorkerAsync()
Catch ex As Exception
MsgBox(ex)
End Try
End If
If ListBox2.SelectedIndex = ListBox2.Items.Count - 1 Then
MsgBox("Proxy Checking Finish")
Else
End If
End Sub
Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
Dim tcount As Integer = 0
tcount = ThreadCount - ListBox2.Items.Count - 1
If ThreadCount > ListBox2.Items.Count Then
ThreadCount = ThreadCount - tcount
Label26.Text = ThreadCount - 1
For i As Integer = 0 To ThreadCount - 1
On Error Resume Next
Dim ch As New Thread(AddressOf CheckProxy)
On Error Resume Next
ch.IsBackground = True
On Error Resume Next
ch.Start()
Next
Else
For i As Integer = 0 To ThreadCount
Dim ch As New Thread(AddressOf CheckProxy)
ch.IsBackground = True
ch.Start()
Next
End If
End Sub
Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
Label17.Text = "stoped"
End Sub
Sub CheckProxy()
Dim req As HttpWebRequest
Dim resp As HttpWebResponse
Dim tString As String
Dim Sw As New Stopwatch
While ListBox2.SelectedIndex = ListBox2.Items.Count - 1
If Label17.Text = "stoped" Then
Exit Sub
Else
End If
Try
tString = ListBox2.SelectedItem
req = HttpWebRequest.Create("http://www.google.com")
req.Proxy = New WebProxy(tString)
req.Timeout = 5000
Sw.Start()
resp = req.GetResponse
Sw.Stop()
If Sw.Elapsed.Seconds = "0" Then
ListBox5.Items.Add(tString)
Label7.Text = ListBox5.Items.Count
ElseIf Sw.Elapsed.Seconds = "1" Then
ListBox4.Items.Add(tString)
Label6.Text = ListBox4.Items.Count
ElseIf Sw.Elapsed.Seconds = "2" Or "3" Or "4" Or "5" Then
ListBox3.Items.Add(tString)
Label4.Text = ListBox3.Items.Count
End If
Label21.Text = ListBox5.Items.Count + ListBox4.Items.Count + ListBox3.Items.Count
If Label17.Text = "stoped" Then
Exit Sub
Else
End If
Catch ex As Exception
Label19.Text += 1
Finally
req = Nothing
resp = Nothing
Sw.Reset()
End Try
Label16.Text = ListBox2.SelectedIndex
ListBox2.SelectedIndex += 1
End While
End Sub
#End Region

New Topic/Question
Reply



MultiQuote





|