全局线程 改变窗体控件值,改变不了或者出错
泡面的幸福 2018-01-06 03:55:18 有一个窗体,form1 ,窗体上有一个按钮一个文本框,Button1和textbox1 有一个模块:Module1
目的:按下按扭,启动线程,调用模块一个过程,过程通过委托,改变窗体上文本框的值,textbox1.text="123"
环境:framework 4.61
按扭代码入下:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As New Thread(AddressOf read)
i.IsBackground = True
i.Start()
End Sub
Module1代码如下:
Module Module1
Private Delegate Sub mydelpad()
Public Sub read()
Dim readstr() As String
Try
While True
Dim str As String = "ReplyReplyuser&true"
If str <> "" Then
readstr = str.Split("&")
If readstr(0) = "ReplyReplyuser" Then
Dim retRepl As Boolean = readstr(1)
If retRepl = True Then
Dim bby As New mydelpad(AddressOf Returncontrolvalue)
Form1.Invoke(bby)
Exit While
End If
End If
End If
End While
Catch ex As Exception
End Try
End Sub
Public Sub Returncontrolvalue()
Form1.TextBox1.Text = "123"
End Sub
End Module