结束不了??? ( 积分: 50 )

问题主要在内层循环中,修改如下:
procedure mmthread.execute()
begin
while not terminateddo
begin
while [red]not terminated [/red]do
begin
..............
end;
..............
end;
end;
 
其实你的那个内循环可以不要的啊~~~
第一重就够了的~~~

分析一下原来的代码:
1、创建thread时,执行第一次
while1 -> while2
while2 一直循环直到一个特定条件后退出while2
即使是退出了while2,这时转到while1 ,while1成立,又进入while2 ,当然while2也成立了,又进入下一次相同的循环,所以死的,一直都在循环中
 
我的目的是在窗口界面中控制线程的结束和在线程中控制线程的结束!不只是退出里面那个循环,而是全部退出线程!
 
即使是再次进入了while 2但这个循环还是属于线程撒,为什么执行.terminate结束不了呢?
 
对呀,没问题呀~~~
你直接用一个外循环有问题吗??都被你弄糊涂了
你内嵌一个循环,你界面上根本还没来得及点那个终止,就有进入第二次循环了。。
 
procedure mmthread.execute()
begin
while not terminateddo
begin
while [red]not terminated [/red]do
begin
..............
end;
..............
end;
end;
好象不行
 
就是进入了里面那个循环也可以用terminate结束撒,因为里面那个循环也是属于线程的撒!不管线程的代码执行到什么地方了都可以结束撒???
 
to hongxing_dl
我用的是D6,你不要说我那个程序在你机器的Delphi7上,terminate按钮也可以正常工作哈?不会是因为版本不同就不行撒,难道D6和D7差异这么大???
 
看了半天没看懂,你用while truedo
是什么意思?
 
一直接收用户的输入,直到用户输入#为止
 
可以结束的啊,
线程先挂起终止就可以了啊。。
 
我是用的两个循环就terminate不下来了,一个循环我试了的可以正常的ter下来.我用的是Delphi6,是不是因为版本不如Delphi7哟?哪位是用Delphi7的帮我试下:
procedure mmthread.execute()
begin
while not terminateddo
begin
while truedo
begin
form1.edit1.text:=inttostr(i);
i:=i+1;
sleep(500);
end;
end;
end;
主窗口form1:
my:mmthread;
用my.terminate看线程是否能停下来?()
帮我用delphi7试一下(这种线程是两个循环的,而且有个是死循环)谢谢!!!
 
你先挂起,然后在终止啊,我说的很清楚的啊,你试了我说的方法了没?
 
赛特:
拜托先看看Terminate函数是什么作用。
procedure Terminate;
Description
Terminate sets the thread's Terminated property to true, signaling that the thread should be terminated as soon as possible.
For Terminate to work, the thread's Execute method and any methods that Execute calls should check Terminated periodically and exit when it's true.
Terminate只是用来设置Terminated属性为true,表示线程现在允许终止。而要free线程必须退出线程的execute方法。
 
tv_getdtmfchar(0)这个函数是怎么写的啊?
贴出来让我学一下啊。。
 
to 来如风:那是语音卡提供的.dll文件里的函数
to flamboyant:
假如my:=mmthread.create(false);
该如何停,并释放资源,写具体点?
 
是不是两个循环都写成:
while not terminateddo
begin
.........
while not terminateddo
bein
........
end;
end;

这样,外面调用my.terminate;就可以终止线程了?需不需要再来个my.free释放资源?
 
while not terminateddo
begin
.........
while not terminateddo
bein
........
end;
end;
[red]这个答案我已经跟你讲了。[/red]
my.terminate终止线程并不等于my对象被释放,因此你必须经my.free释放资源。
另外my.terminate后你必须进行my.waitfor以等待线程的结束,然后才能my.Free以释放资源。
 
my.suspand;//好象是这么拼的。。
my.terminate;
这样可以直接结束掉的。。
回家了。。
 
to abookdog:
my.waitfor 是怎么用的?
my.terminate;
my.waitfor;
my.free;
就是这么写的结束语句?
 

Similar threads

S
回复
0
查看
950
SUNSTONE的Delphi笔记
S
D
回复
0
查看
739
DelphiTeacher的专栏
D
S
回复
0
查看
774
SUNSTONE的Delphi笔记
S
D
回复
0
查看
682
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
顶部