好库网 好库网首页 | 我的好库
Delphi盒子

如何终止一个线程-Delphi资料

发布者:delphibox
发布日期:2011/4/8 22:33:49   更新日期:2011/4/8 22:33:49
阅读次数:3037
评分:4.80
介绍: 如何终止一个线程-Delphi资料
正文:

You can Terminate your thread in two ways:

1) Assign ThreadDone to OnTerminate when you create it.

In the Execute method

exit when the terminated property is True.

At the point where you want to stop

issue the Terminate method.

2) Just call the Suspend method.

After one of these steps you may free the thread.

I hope the following snippets will help.

// -------------------------------------------------------------- //

interface

type

Txyz = class(TThread)

published

procedure Execute; override;

end;

var

XYZThread: Txyz;

implementation

procedure Txyz.Execute;

begin

while True do Application.ProcessMessages;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

XYZThread := Txyz.Create(False);

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

XYZThread2.Suspend;

XYZThread2.Free;

end;


评论 [发表评论]
账号 密码 还没帐号呢,现在注册一个?

免责声明:好库网所展示的信息由买卖双方自行提供,其真实性、准确性和合法性由信息发布人负责。好库网不提供任何保证,并不承担任何法律责任。