| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 568 人关注过本帖
标题:[求助]多线程
只看楼主 加入收藏
Magicalsoft
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-12-16
收藏
 问题点数:0 回复次数:3 
[求助]多线程

先看段代码:
Dim t1 As Thread
Dim t2 As Thread
Private Sub Process1()
Dim i As Integer = 1
Do While True
ProgressBar1.Value = i
i += 1
If i = 10000 Then
i = 1
End If
Loop
'为了让用户看清进度条的进度,将线程处理速度变慢
Thread.Sleep(2)
End Sub
Private Sub Process2()
Dim i As Integer = 1
Do While True
ProgressBar2.Value = i
i += 1
If i = 10000 Then
i = 1
End If
Loop
'为了让用户看清进度条的进度,将线程处理速度变慢
Thread.Sleep(2)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t1 = New Thread(AddressOf Process1)
t1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
t1.Abort()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
t2 = New Thread(AddressOf Process2)
t2.Start()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
t2.Abort()
End Sub


为什么这段代码在 VS2003里正确运行,在VS2005中就不对了呢?发生了以下错误:Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on.

搜索更多相关主题的帖子: 线程 
2005-12-28 13:33
Magicalsoft
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-12-16
收藏
得分:0 
没人看看吗?

Me.菜鸟 = True
2005-12-28 13:51
luoshun
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2005-11-17
收藏
得分:0 

看了不懂,所以就不敢乱发表意见啦,老大!

2005-12-30 11:58
lxtf214
Rank: 1
等 级:新手上路
帖 子:151
专家分:0
注 册:2005-12-29
收藏
得分:0 
是VB.NET啊!
不会.

(.NET Programmer ) 要为成功找方法,不为失败找理由
2005-12-30 13:08
快速回复:[求助]多线程
数据加载中...
 
   



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

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