uRe: Why doesn't my thread terminate?



Ok,

You probably doing many things wrong, here is a example/snippet how it
could/should look like:

type
TMyThread = ...
mStart : TnotifyEvent;
mStop : TnotifyEvent;
mUpdateEditBox : TnotifyEvent;

etc;

end;

procedure TMyThread.DoStart;
begin
if Assigned(mStart) then mStart(Self);
end;

procedure TMyThread.DoStop;
begin
if Assigned(mStop) then mStop(Self);
end;

procedure TMyThread.DoUpdateEditBox;
begin
if Assigned(mUpdateEditBox) then mUpdateExitBox(Self);
end;

procedure TMyThread.Execute;
begin

// fire start event
Synchronize(DoStart);

while not Terminated do
begin

// timing code goes here, for example:
sleep( 1000 );

// or for more precision see query performance counter api.

// fire update event
Synchronize(DoUpdateEditBox);

end;

// fire stop event
Synchronize(DoStop);
end;


Then in the button event handlers when you wanna stop the thread write
something like:

MyThread.Terminate;

Bye,
Skybuck.


.