不要用sleep函数啊,我用了它之后暂停那几秒的时候那程序就好像死机一样,要暂停过后才有反应的.现在我想要一个暂停的时候那个程序也可以运行的函数.
线程1:
while true do begin
...
sleep(5000); //这暂停的五秒程序就好像死了那样不动了,我需要这段时间也可以按其它按钮什么的.
end;
...全文
29417打赏收藏
介绍个让线程暂停几秒运行的函数.
不要用sleep函数啊,我用了它之后暂停那几秒的时候那程序就好像死机一样,要暂停过后才有反应的.现在我想要一个暂停的时候那个程序也可以运行的函数. 线程1: while true do begin ... sleep(5000); //这暂停的五秒程序就好像死了那样不动了,我需要这段时间也可以按其它按钮什么的. end;
procedure Tmythread1.search;
begin
{ Place thread code here }
if Form1.flag1 then begin
Application.ProcessMessages;
sleep(Form1.settime1);
Terminate;//处理完成后,一定要中断线程
end;
end;
procedure Tmythread1.Execute;
begin
{ Place thread code here }
// search;// 如果search过程只需运行一次,就加在这里,取消循环中的调用
while Not Terminated do
begin
Application.ProcessMessages;
search;
end;
end;
procedure Tmythread1.Execute;
begin
{ Place thread code here }
while Not(Form1.flag1) or (Not Terminated) do
begin
Application.ProcessMessages;
end;
end;