My code
Imports System.IO
Public Class Form1
Dim thread As System.Threading.Thread
Dim thread2 As System.Threading.Thread
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
thread = New System.Threading.Thread(AddressOf getproxy)
thread.Start()
End Sub
Private Sub getproxy()
Try
Dim ip As String = "76.125.85.66:16805 | 0.238 | Little Rock | AR | Unknown | United States69.207.212.76:49233 | 0.274 | Sayre | PA | 18840 | United States96.42.127.190:25480 | 0.292 | Sartell | MN | 56377 | United States"
For Each m As Match In Regex.Matches(ip, "(?:\d{1,3}\.){3}\d{1,3}:\d+")
TextBox1.Text += (m.Value) & vbNewLine
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
我希望它显示文本框所有代理格式
76.125.85.66:16805
69.207.212.76:49233
96.42.127.190:25480
但它错误
{“跨线程操作无效:从创建它的线程以外的线程访问控制“TextBox1”。”}
一旦启动线程,您就无法从 UI 线程访问控制权。你可以UI 线程并更新文本框。
Private Sub getproxy()
Dim ip As String = "76.125.85.66:16805 | 0.238 | Little Rock | AR | Unknown | United States69.207.212.76:49233 | 0.274 | Sayre | PA | 18840 | United States96.42.127.190:25480 | 0.292 | Sartell | MN | 56377 | United States"
Me.Invoke(Sub()
For Each m As Match In Regex.Matches(ip, "(?:\d{1,3}\.){3}\d{1,3}:\d+")
TextBox1.Text += (m.Value) & Enviroment.NewLine
Next
End Sub)
End Sub
PS 为什么这项工作需要线程?看来这需要很少的时间来执行。线程用于长时间的进程工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)