说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

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

HTML文档下载 WORD文档下载 PDF文档下载
如何终止一个线程-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;

备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘