发信人: redfox (Z掉了几乎所有的版...), 信区: BorlandDev
标 题: Delphi编程 -- 6.18 停止一个线程
发信站: 哈工大紫丁香 (2000年09月01日16:28:39 星期五), 站内信件
停止一个线程?
问 Stop A Thread?
回答
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;
end.
--
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.227.107]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:9.122毫秒