以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关于System.Threading.Thread.Sleep  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=47826)

--  作者:zhouly619
--  发布时间:2014/3/18 11:50:00
--  关于System.Threading.Thread.Sleep

我在代码中用自定义函数之间加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
--  发布时间:2014/3/18 11:53:00
--  
睡眠就会把当前进程睡眠,当然就会卡住不动了.

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