Foxtable(狐表)用户栏目专家坐堂 → 关于System.Threading.Thread.Sleep


  共有4341人关注过本帖树形打印复制链接

主题:关于System.Threading.Thread.Sleep

帅哥哟,离线,有人找我吗?
zhouly619
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:91 积分:1785 威望:0 精华:0 注册:2012/8/28 14:53:00
关于System.Threading.Thread.Sleep  发帖心情 Post By:2014/3/18 11:50:00 [只看该作者]

我在代码中用自定义函数之间加System.Threading.Thread.Sleep 程序就停着不动,一直要强制关闭才可以

 

代码如下

Dim D1 As Date = Date.Now
Dim s As String
Dim s1 As String
Dim s2 As String
s = Functions.Execute("CaRio",0,"m0",0,1) ’ 自定义函数
s1 = Functions.Execute("CaReal",s) ’自定义函数
Functions.Execute("FONF",s1) ’自定义函数


System.Threading.Thread.Sleep(300)

 

s2 = Functions.Execute("ReNF") ’自定义函数
e.Form.Controls("Label1").text = s2
Dim D2 As Date = Date.Now
Dim t As TimeSpan = d2 - d1
MessageBox.Show(t.TotalSeconds)

 

但是当我在System.Threading.Thread.Sleep的前面加上messagebox的时候程序又正常了,代码如下

Dim D1 As Date = Date.Now
Dim s As String
Dim s1 As String
Dim s2 As String
s = Functions.Execute("CaRio",0,"m0",0,1) ’ 自定义函数
s1 = Functions.Execute("CaReal",s) ’自定义函数
Functions.Execute("FONF",s1) ’自定义函数

MessageBox.Show(1)
System.Threading.Thread.Sleep(300)

 

s2 = Functions.Execute("ReNF") ’自定义函数
e.Form.Controls("Label1").text = s2
Dim D2 As Date = Date.Now
Dim t As TimeSpan = d2 - d1
MessageBox.Show(t.TotalSeconds)

 

求解啊


 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/3/18 11:53:00 [只看该作者]

睡眠就会把当前进程睡眠,当然就会卡住不动了.

2个方案
1.改用多线程,对于一般用户来说非常复杂
2.用计时器来完成.

 回到顶部