| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 231 人关注过本帖
标题:敬请各位高手解决vb.net(VS2010)多线程的问题。谢谢。
只看楼主 收藏
HVB6
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:6
帖 子:262
专家分:374
注 册:2013-10-30
结帖率:100%
  已结贴   问题点数:20  回复次数:1   
敬请各位高手解决vb.net(VS2010)多线程的问题。谢谢。
以下代码在vb.net(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
2017-07-16 16:53
zhangcanwei
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:4
帖 子:53
专家分:135
注 册:2010-7-4
  得分:20 
线程的启动时需要时间的,当线程还没有完全启动时,MessageBox.Show()这句,就开始运行了,那肯定是得不到结果的
2017-07-17 16:57







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.082138 second(s), 9 queries.
Copyright©2004-2017, BCCN.NET, All Rights Reserved