vb.net 多线程 如何在另一窗口并发执行 10
例如ImportsSystem.ThreadingPublicClassForm1Dimt1,t2AsThreadDimtt1PrivateDelegateSubvoid...
例如
Imports System.Threading
Public Class Form1
Dim t1, t2 As Thread
Dim tt1
Private Delegate Sub voiddelegate()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Form2.Show()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t1 = New Thread(AddressOf test)
tt1 = 1
t1.Start()
tt1 = 2
t2 = New Thread(AddressOf test)
t2.Start()
End Sub
Private Sub updateui()
For i = 0 To 9000
Application.DoEvents()
If tt1 = 1 Then
Form2.Label1.Text = i.ToString
Else
Form2.Label2.Text = i.ToString
End If
Next
End Sub
Private Sub test()
Me.Invoke(New voiddelegate(AddressOf updateui))
End Sub
End Class
这样只会刷新Label2的值 展开
Imports System.Threading
Public Class Form1
Dim t1, t2 As Thread
Dim tt1
Private Delegate Sub voiddelegate()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Form2.Show()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t1 = New Thread(AddressOf test)
tt1 = 1
t1.Start()
tt1 = 2
t2 = New Thread(AddressOf test)
t2.Start()
End Sub
Private Sub updateui()
For i = 0 To 9000
Application.DoEvents()
If tt1 = 1 Then
Form2.Label1.Text = i.ToString
Else
Form2.Label2.Text = i.ToString
End If
Next
End Sub
Private Sub test()
Me.Invoke(New voiddelegate(AddressOf updateui))
End Sub
End Class
这样只会刷新Label2的值 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询