none
arreter le threads RRS feed

  • Question

  • Bonjour, a tous!!

    je suis tomber sur un petit problème pour arrêter le threads.

    Imports System.IO
    Imports System.Net
    Imports System.Text
    Imports System.Threading
    
    Public Class Form1
        Dim index As Integer = 1
        Dim proxies As New List(Of String)
        Dim WithEvents wc As New WebClient
        Dim Mythreads As Thread
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim fo As New OpenFileDialog
            fo.RestoreDirectory = True
            fo.Multiselect = False
            fo.Filter = "txt files (*.txt)|*.txt"
            fo.FilterIndex = 1
            If fo.ShowDialog = Windows.Forms.DialogResult.OK Then
                proxies.Clear()
                Using sr As New StreamReader(fo.FileName)
                    While sr.Peek <> -1
                        proxies.Add(sr.ReadLine())
                        Label6.Text = proxies.Count
                    End While
                End Using
            End If
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Mythreads.Abort()
        End Sub
    
        Private Function VericationProxy(proxy As String) As Boolean
            Try
                wc.Encoding = Encoding.UTF8
                wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36")
                wc.Proxy = New WebProxy(proxy)
                wc.DownloadString("https://www.google.fr/")
                Return True
            Catch
                Return False
            End Try
            Return False
        End Function
    
        Private Sub CheckProxy()
            While index > 0
                If index >= proxies.Count Then
                    Exit While
                Else
                    Dim proxy As String = proxies(index)
                    If VericationProxy(proxy) Then
                        Label4.BeginInvoke(New Action(Sub() Label4.Text = index))
                    Else
                        Label2.BeginInvoke(New Action(Sub() Label2.Text = index))
                    End If
                    Math.Max(System.Threading.Interlocked.Increment(index), index - 1)
                End If
            End While
            Mythreads.Abort()
            MsgBox("Traitement Traité !", MsgBoxStyle.Information, "Traitement")
        End Sub
    
        Private Sub B_Click(sender As System.Object, e As System.EventArgs) Handles B.Click
            For i = 0 To NumericUpDown1.Value
                Mythreads = New Thread(AddressOf CheckProxy)
                Mythreads.IsBackground = True
                Mythreads.Start()
            Next
        End Sub
    End Class
    Pouvez-vous me dire comme arrêter le threads et rependre le threads.

    dimanche 11 avril 2021 07:56

Toutes les réponses