vb 网络线程/类问题
大家好,我已经发布了有关此问题的文章,并且使用了答案来帮助我,但我仍然陷入困境,我真的要克服这个问题并继续我的程序的其余部分。我正在尝试使用另一个线程上另一个类的新文本更新文本框。我可以让它在同一类的另一个线程上以及另一个类的同一线程上毫无问题地工作。但不在另一个类的另一个线程上。我的代码看起来像这样,当它运行时不产生错误但不将测试添加到文本框中,奇怪的是我对程序进行了一些更改以将多行添加到 consolebox.text 然后检查 console.text来自 form2 并生成我添加的值,但由于某种原因这些值没有反映在控制台框中。有人请帮助我,这样我就可以不再打扰你了...哈哈
Public Class Form1
Dim myform2 As New form2
Dim t As New System.Threading.Thread(AddressOf myform2.display)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Delegate Sub ConsoleDelegate(ByVal message As String)
Public Sub console(ByVal message As String)
If Me.InvokeRequired Then
Me.Invoke(New ConsoleDelegate(AddressOf console), New Object() {message})
Return
End If
If Me.consolebox.Text.Length > 0 Then
If Me.consolebox.Text.Substring(Me.consolebox.Text.Length - 3, 3) = "..." Then
Me.consolebox.AppendText(message)
ElseIf Me.consolebox.Text.Substring(Me.consolebox.Text.Length - 1, 1) = "." Then
Me.consolebox.AppendText(ControlChars.NewLine & timestamp() & message)
End If
Else
Me.consolebox.AppendText(timestamp() & message)
End If
End Sub
Function timestamp()
Return "[DATE]"
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t.Start()
End Sub
结束课程
公共课程 form2
Public Sub display()
Form1.console("hello")
End Sub
结束课程
Hi guys ive already posted about this and ive used the answers to help me, but im still stuck and i really to get past this and move onto the rest of my program. I'm trying to update a textbox with new text from another class on another thread. I can get this to work no problem on another thread with the same class, and on the same thread in another class. but not on another thread on another class. my code looks like this, when it is run to produces no errors but does not add the test to the text box, what is wierd is i had made some changes to the program to add multiplelines to consolebox.text and then checked console.text from form2 and it produces the values i added but those arent reflected inside in the consolebox for some reason. Someone please help me so i can stop bothering you... lol
Public Class Form1
Dim myform2 As New form2
Dim t As New System.Threading.Thread(AddressOf myform2.display)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Delegate Sub ConsoleDelegate(ByVal message As String)
Public Sub console(ByVal message As String)
If Me.InvokeRequired Then
Me.Invoke(New ConsoleDelegate(AddressOf console), New Object() {message})
Return
End If
If Me.consolebox.Text.Length > 0 Then
If Me.consolebox.Text.Substring(Me.consolebox.Text.Length - 3, 3) = "..." Then
Me.consolebox.AppendText(message)
ElseIf Me.consolebox.Text.Substring(Me.consolebox.Text.Length - 1, 1) = "." Then
Me.consolebox.AppendText(ControlChars.NewLine & timestamp() & message)
End If
Else
Me.consolebox.AppendText(timestamp() & message)
End If
End Sub
Function timestamp()
Return "[DATE]"
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t.Start()
End Sub
End Class
Public Class form2
Public Sub display()
Form1.console("hello")
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将
Form1
的实例传递给form2
:和 form2:
You have to pass the instance of
Form1
toform2
:and form2: