当前位置:主页>delphi7/进销存和数据库> 文章内容

结束不了???

发布时间:2010-01-27 | QQ免费站
1楼: 我的线程有个双循环: procedure mmthread.execute() begin while not terminated do begin while true do begin .............. end; end; end; my:mmthread; 1.调用my.terminate属性为true停不了线程???? 2.用terminate为true停线程就不用再来个my.free了撒???? 3.用my.suspend,再my.free后,程序就死起了,按键也按不起了???? 字串8

2楼: 1. while true 是死循环,需要在里面加入 break 或 goto 等跳转语句。 2.设置Thread对象的FreeOnTerminate属性为True才有次效果. 3.一个线程没有结束,一般不要强行Free,会有很多问题。
字串2

3楼: 在线程的外面怎样结束?

字串4

4楼: 在调用terminate属性为true 后那还要.free才能释放资源哟? 字串1

5楼: 我试过了如果线程就是: while not terminated do begin ............... end; 只是一个循环的话,terminate为true就能正常的结束线程

字串1

6楼: 怎么会用while true 这样的语句呢 思路问题 字串5

7楼: 那当然,你在一层循环里包一个死循环没意义。
字串2

8楼: 是的,死循环了~~~第一次判断没有terminated 后就已经进入 while true do死循环了,根本跳不出来 字串7

9楼: 我做的毕业设计是个电话语音服务系统。语音卡有两个通道,我的设计是一个通道是一个线程。但我发现用到双循环后,用线程对象的terminate属性为true就停不了了?? 我线程是这样的: while not terminated do //最外层循环是一直不停的让它监 begin //听通道 。。。。。。。。 while true do //内层这个循环是判断用户只要不输入#号 begin //就记录用户的输入(用户输入以#结束) case tv_getdtmfchar(0) of //该函数返回输入的asc码 48:yonghushuru:=yonghushuru+‘1‘; 49:yonghushuru:=yonghushuru+‘2‘; ................ 35:break; else end; end; end; 1.但在调用该线程对象的terminate为true时就停不了了,我试过的单循环就可以正常的停???? 2.用terminate为true停线程就不用再来个 线程对象.free 了撒???? 3.用对象.suspend,再对象.free后,程序就死起了,按键也按不起了???? 谢谢了!! 字串3

10楼: while true do //内层这个循环是判断用户只要不输入#号 begin //就记录用户的输入(用户输入以#结束) application.ProcessMessages;//加上这句,不然死定了 :) case tv_getdtmfchar(0) of //该函数返回输入的asc码 48:yonghushuru:=yonghushuru+‘1‘; 49:yonghushuru:=yonghushuru+‘2‘; ................ 35:break; else end; end; 如果加上那句还不行,再把 35:break;改为Exit试试??

字串2

11楼: exit 就跳出这个事件了

字串1

12楼: 那在while true do的循环体中加上application.ProcessMessages;这句就应该可以了~~~试试吧~~~ 字串2

13楼: 写具体点呀,我是初学线程 字串6

14楼: 我上面已经写了啊,没注意看吧?:) while true do begin application.ProcessMessages;//加上这句,意思是交主动权给windows case tv_getdtmfchar(0) of 48:yonghushuru:=yonghushuru+‘1‘; 49:yonghushuru:=yonghushuru+‘2‘; ................ 35:break; else end; end;
字串8

15楼: 2.用terminate为true停线程就不用再来个my.free了撒???? 3.用my.suspend,再my.free后,程序就死起了,按键也按不起了???? 字串9

16楼: 加了application.ProcessMessages,后在线程里面也是线程对象.terminate属性为true来结束是不是?之后不用再.free了撒???? 字串8

17楼: 给我你的邮箱嘛,我发个简单的线程双循环来,帮我调试一下,谢谢
字串4

18楼: hongxing_dl724@163.com 我先午休一下下,你先发过来吧。 我用的d7

字串7

19楼: 我已经给你发到邮箱了,谢谢!!!

字串4

20楼: 问题主要在内层循环中,修改如下: procedure mmthread.execute() begin while not terminated do begin while [red]not terminated [/red] do begin .............. end; .............. end; end; 字串8

21楼: 其实你的那个内循环可以不要的啊~~~ 第一重就够了的~~~ 分析一下原来的代码: 1、创建thread时,执行第一次 while1 -> while2 while2 一直循环直到一个特定条件后退出while2 即使是退出了while2,这时转到while1 ,while1成立,又进入while2 ,当然while2也成立了,又进入下一次相同的循环,所以死的,一直都在循环中
字串4

22楼: 我的目的是在窗口界面中控制线程的结束和在线程中控制线程的结束!不只是退出里面那个循环,而是全部退出线程! 字串5

23楼: 即使是再次进入了while 2但这个循环还是属于线程撒,为什么执行.terminate结束不了呢? 字串5

24楼: 对呀,没问题呀~~~ 你直接用一个外循环有问题吗??都被你弄糊涂了 你内嵌一个循环,你界面上根本还没来得及点那个终止,就有进入第二次循环了。。

字串7

25楼: procedure mmthread.execute() begin while not terminated do begin while [red]not terminated [/red] do begin .............. end; .............. end; end; 好象不行 字串1

26楼: 就是进入了里面那个循环也可以用terminate结束撒,因为里面那个循环也是属于线程的撒!不管线程的代码执行到什么地方了都可以结束撒???

字串6

27楼: to hongxing_dl 我用的是D6,你不要说我那个程序在你机器的Delphi7上,terminate按钮也可以正常工作哈?不会是因为版本不同就不行撒,难道D6和D7差异这么大??? 字串6

28楼: 看了半天没看懂,你用while true do 是什么意思?
字串2

29楼: 一直接收用户的输入,直到用户输入#为止

字串4

30楼: 可以结束的啊, 线程先挂起终止就可以了啊。。 字串5

31楼: 我是用的两个循环就terminate不下来了,一个循环我试了的可以正常的ter下来.我用的是Delphi6,是不是因为版本不如Delphi7哟?哪位是用Delphi7的帮我试下: procedure mmthread.execute() begin while not terminated do begin while true do begin form1.edit1.text:=inttostr(i); i:=i+1; sleep(500); end; end; end; 主窗口form1: my:mmthread; 用my.terminate看线程是否能停下来?() 帮我用delphi7试一下(这种线程是两个循环的,而且有个是死循环)谢谢!!! 字串6

32楼: 你先挂起,然后在终止啊,我说的很清楚的啊,你试了我说的方法了没? 字串4

33楼: 赛特: 拜托先看看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方法。 字串5

34楼: tv_getdtmfchar(0)这个函数是怎么写的啊? 贴出来让我学一下啊。。
字串9

35楼: to 来如风:那是语音卡提供的.dll文件里的函数 to flamboyant: 假如my:=mmthread.create(false); 该如何停,并释放资源,写具体点? 字串8

36楼: 是不是两个循环都写成: while not terminated do begin ......... while not terminated do bein ........ end; end; 这样,外面调用my.terminate;就可以终止线程了?需不需要再来个my.free释放资源? 字串8

37楼: while not terminated do begin ......... while not terminated do bein ........ end; end; [red]这个答案我已经跟你讲了。[/red] my.terminate终止线程并不等于my对象被释放,因此你必须经my.free释放资源。 另外my.terminate后你必须进行my.waitfor以等待线程的结束,然后才能my.Free以释放资源。

字串1

38楼: my.suspand;//好象是这么拼的。。 my.terminate; 这样可以直接结束掉的。。 回家了。。 字串8

39楼: to abookdog: my.waitfor 是怎么用的? my.terminate; my.waitfor; my.free; 就是这么写的结束语句? 字串3

40楼: 多人接受答案了。 字串8