| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2959 人关注过本帖
标题:敬请各位高手解决vb.net(VS2010)多线程的问题。谢谢。
只看楼主 加入收藏
HVB6
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:331
专家分:561
注 册:2013-10-30
结帖率:98.41%
收藏
已结贴  问题点数:20 回复次数:2 
敬请各位高手解决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
搜索更多相关主题的帖子: Private Sub End Thread Threading 
2017-07-16 16:53
zhangcanwei
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:63
专家分:135
注 册:2010-7-4
收藏
得分:20 
线程的启动时需要时间的,当线程还没有完全启动时,MessageBox.Show()这句,就开始运行了,那肯定是得不到结果的
2017-07-17 16:57
无聊时想想你
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2017-7-13
收藏
得分:0 
回复 楼主 HVB6
Public Class Form1
    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()
        t1.Join()
        t2.Join()
        MessageBox.Show("a=" & a & ",b=" & b)
    End Sub

End Class
收到的鲜花
  • HVB62017-12-23 17:18 送鲜花  8朵   附言:好文章
2017-12-22 14:49
快速回复:敬请各位高手解决vb.net(VS2010)多线程的问题。谢谢。
数据加载中...
 
   



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

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