敬请各位高手解决vb.net(VS2010)多线程的问题。谢谢。
以下代码在(VS2010)测试正常。Private a As Integer
Private b As Integer
Private Sub setA()
a = 1
End Sub
Private Sub setB()
b = 2
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t1 As Threading.Thread
Dim t2 As Threading.Thread
t1 = New Threading.Thread(AddressOf setA)
t2 = New Threading.Thread(AddressOf setB)
t1.Start()
t2.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MessageBox.Show ("a=" & a & ",b=" & b)
End Sub
问题:如何只用一个按钮可以实现以上代码的功能?以下代码不能实现以上代码的功能。
Private a As Integer
Private b As Integer
Private Sub setA()
a = 1
End Sub
Private Sub setB()
b = 2
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t1 As Threading.Thread
Dim t2 As Threading.Thread
t1 = New Threading.Thread(AddressOf setA)
t2 = New Threading.Thread(AddressOf setB)
t1.Start()
t2.Start()
MessageBox.Show ("a=" & a & ",b=" & b)
End Sub