关于vb.net 多线程和委托问题
DimnnAsIntegerDimTdAsSystem.Threading.Thread'定义一个线程DelegateSubMySubDelegate()Classcla...
Dim nn As Integer
Dim Td As System.Threading.Thread '定义一个线程
Delegate Sub MySubDelegate()
Class class1
Sub Sub1()
Form1.Timer1.Enabled = True
Form1.Label1.Visible = True
MsgBox("kkk")
End Sub
End Class
Private Sub DelegateTest()
Dim c1 As New class1
Dim msd As MySubDelegate = AddressOf c1.Sub1
msd.Invoke()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Td = New System.Threading.Thread(AddressOf DelegateTest)
Td.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If nn <= 5 Then
nn = nn + 1
Label1.Text = Label1.Text & "."
Else
nn = 0
Label1.Text = "数据加载中"
End If
End Sub
我点击“Button1”键后,为什么只执行: MsgBox("kkk")语句,而Form1.Timer1.Enabled = True和Form1.Label1.Visible = True语句却没有执行,郁闷得很。 展开
Dim Td As System.Threading.Thread '定义一个线程
Delegate Sub MySubDelegate()
Class class1
Sub Sub1()
Form1.Timer1.Enabled = True
Form1.Label1.Visible = True
MsgBox("kkk")
End Sub
End Class
Private Sub DelegateTest()
Dim c1 As New class1
Dim msd As MySubDelegate = AddressOf c1.Sub1
msd.Invoke()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Td = New System.Threading.Thread(AddressOf DelegateTest)
Td.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If nn <= 5 Then
nn = nn + 1
Label1.Text = Label1.Text & "."
Else
nn = 0
Label1.Text = "数据加载中"
End If
End Sub
我点击“Button1”键后,为什么只执行: MsgBox("kkk")语句,而Form1.Timer1.Enabled = True和Form1.Label1.Visible = True语句却没有执行,郁闷得很。 展开
展开全部
Delegate Sub MySubDelegate(form As Form1)
Class class1
Sub Sub1(form As Form1)
form.Timer1.Enabled = True
form.Label1.Visible = True
MsgBox("kkk")
End Sub
End Class
Private Sub DelegateTest()
Dim c1 As New class1
Dim msd As MySubDelegate = AddressOf c1.Sub1
Me.Invoke(msd,Me)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询