.Net中的线程池错误无效的跨线程操作

.Net中的线程池错误无效的跨线程操作,.net,vb.net,multithreading,.net,Vb.net,Multithreading,今天,当我试图在Backgroundworker中以列表框为目标创建线程池时,出现了一个异常,有人可以帮助我吗´:) 这是我瞄准的潜艇: Private Sub ScrapProxy() Dim webClient As WebClient = New WebClient() Dim list As List(Of String) = New List(Of String)() Try For Each text As String In Me.T

今天,当我试图在Backgroundworker中以列表框为目标创建线程池时,出现了一个异常,有人可以帮助我吗´:)

这是我瞄准的潜艇:

    Private Sub ScrapProxy()
    Dim webClient As WebClient = New WebClient()
    Dim list As List(Of String) = New List(Of String)()
    Try
        For Each text As String In Me.TextBox1.Lines
            Dim input As String = webClient.DownloadString(text)
            Me.CSP = text
            Dim matchCollection As MatchCollection = REGEX.Matches(input)
            For Each obj As Object In matchCollection
                Dim match As Match = CType(obj, Match)
                TextBox2.AppendText(match.ToString & Environment.NewLine)
                Me.ProxyAmount = Convert.ToInt32(Me.LB_GatheredProxies.Items.Count)
            Next
            Dim flag As Boolean = Not Me.LB_Logs.Items.Contains(text)
            If flag Then
                Me.ListBox1.Items.Add("[+]Scraped: " + text)
            End If
        Next
    Catch ex As Exception
        Me.ListBox1.Items.Add("[-]Dead Link: " + Me.CSP) **Here i get the exception :c**
    End Try
End Sub
是否有人可以帮助学员或其他人?
向卡什致以最诚挚的问候

您可以停在这一行:

For Each state As String In TextBox1.Lines
不能在与主GUI线程不同的线程中访问GUI元素。这是在另一个线程中调用的,您可以通过函数名来判断:
BackgroundWorker1\u DoWork


您需要调用您的代码并使其慢得令人痛苦,或者从.Net 1中删除后台工作程序,使用/
等待
/
异步

编写正确的现代代码。您可以将字符串数组传递给RunWorkerAsync()接受
对象的
方法重载
参数:它将是
DoWorkEventArgs()中的
DoWorkEventArgs.argument
甚至不要考虑从BackGroundWorker调用()UI线程。将结果传递(锁定)到
[BackgroundWorker].ReportProgress
(设置
BackgroundWorker.WorkerReportsProgress=true
)--使用
任务列表处理这一切要容易得多。顺便说一句,不知道为什么您(实际上还有其他人)在根本不处理此类响应时设置
ServicePointManager.Expect100Continue=True
For Each state As String In TextBox1.Lines