unit MyTestThread;
interface
uses
Classes,SyncObjs;
type
TMyThread = class(TThread)
private
//定义内部对象
FInterval:Integer;
{ Private declarations }
protected
procedure Execute; override;
public
constructor Create(CreateSuspend: Boolean);
destructor Destroy; override;
property Interval:Integer read FInterval write FInterval;
end;
procedure NotifyThreadsToQuit;
var
QuitEvent: TEvent;
implementation
constructor TMyThread.Create(CreateSuspend: Boolean);
begin
inherited;
//创建线程对象
end;
destructor TMyThread.Destroy;
begin
//析构线程对象
inherited;
end;
procedure TMyThread.Execute;
begin
while not Terminated do
begin
//do the procedure;
case QuitEvent.WaitFor(Interval) of
wrSignaled, wrAbandoned: Terminate;
wrTimeOut, wrError: ; // do nothing
end;
end;
{ Place thread code here }
end;
procedure NotifyThreadsToQuit;
begin
QuitEvent.SetEvent;
end;
initialization
QuitEvent := TEvent.Create(nil,True,False,'ThreadQuitEvent');
finalization
QuitEvent.Free;
end.