求写一下vb.net双线程的代码:两个按钮和两个label控件,按钮让label自加,按钮互不干扰
1个回答
展开全部
Imports System
Imports System.Threading
Public Class Form1
Dim TestThread1, TestThread2 As Thread
Public Sub TestMethod1()
Dim i As Integer
i = 0
While (i < 10)
Label1.Text = i
i += 1
End While
End Sub
Public Sub TestMethod2()
Dim i As Integer
i = 0
While (i < 10)
Label2.Text = i
i += 1
End While
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Control.CheckForIllegalCrossThreadCalls = False
TestThread1 = New Thread(New ThreadStart(AddressOf TestMethod1))
TestThread1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Control.CheckForIllegalCrossThreadCalls = False
TestThread2 = New Thread(New ThreadStart(AddressOf TestMethod2))
TestThread2.Start()
End Sub
End Class
更多追问追答
追问
大神,我问一下,如果两个自加变为自己计数的话,不会卡吗
追答
不会卡,因为是两个线程,独立进行的,自己计数的话,有时隙的,也不会卡
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询