3 Replies - 202 Views - Last Post: 07 February 2012 - 06:13 PM Rate Topic: -----

Topic Sponsor:

#1 rahulrhl29  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-February 12

Multithreading proxy checking funtion help

Posted 07 February 2012 - 05:35 PM

Hello Friends,
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



Is This A Good Question/Topic? 0
  • +

Replies To: Multithreading proxy checking funtion help

#2 AdamSpeight2008  Icon User is online

  • Coder-ian
  • member icon

Reputation: 1401
  • View blog
  • Posts: 7,361
  • Joined: 29-May 08

Re: Multithreading proxy checking funtion help

Posted 07 February 2012 - 05:55 PM

Any error messages?
Was This Post Helpful? 0
  • +
  • -

#3 rahulrhl29  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-February 12

Re: Multithreading proxy checking funtion help

Posted 07 February 2012 - 05:58 PM

No the application just stop working at last
Was This Post Helpful? 0
  • +
  • -

#4 rahulrhl29  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-February 12

Re: Multithreading proxy checking funtion help

Posted 07 February 2012 - 06:13 PM

One small mistake over here sorry for that in sub checkproxy()
I have use do until - loop instead of while - end while
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1