谁能分享一下vb.net多线程的简单例子,证明线程之间互不干扰,加上注释最好。
答案:1 悬赏:50 手机版
解决时间 2021-03-31 20:24
- 提问者网友:孤山下
- 2021-03-30 20:52
谁能分享一下vb.net多线程的简单例子,证明线程之间互不干扰,加上注释最好。
最佳答案
- 五星知识达人网友:何以畏孤独
- 2021-03-30 21:42
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扣扣 三 一四 零二 一 一 四 六
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扣扣 三 一四 零二 一 一 四 六
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯