谁能分享一下vb.net多线程的简单例子,证明线程之间互不干扰,加上注释最好。
展开全部
Imports System
Imports System.Threading
Public Class Form1
Dim TestThread1, TestThread2 As Thread
Public Sub TestMethod1()
Dim i As Integer
i = 0
While (i < 1000)
Label1.Text = i
i += 1
End While
End Sub
Public Sub TestMethod2()
Dim i As Integer
i = 0
While (i < 1000)
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
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Control.CheckForIllegalCrossThreadCalls = False
TestThread1 = New Thread(New ThreadStart(AddressOf TestMethod1))
TestThread2 = New Thread(New ThreadStart(AddressOf TestMethod2))
TestThread1.Start()
TestThread2.Start()
End Sub
End Class
追问
兄弟,你要是帮我把上次的问题找到原因,我两个问题都采纳。。
追答
我上次不是给你说 要你发代码的嘛 你一直没有发
或者给我工程 帮你调试好
my扣扣 三 一四 零二 一 一 四 六
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询