Why doesn't my thread terminate?
- From: Prodigal Son <prodigal.son@xxxxxxxxxxx>
- Date: Fri, 02 May 2008 15:42:53 GMT
Hi everybody,
I'm trying to learn a thing or two about threads in Delphi, so I'm
currently messing around with some examples and trying to create a few
simple examples myself.
My current situation is the following: I have a form which has a button,
and an editbox. I'd like to start a thread, and update the editbox at
fixed intervals, from within the thread. But before I even got to that
part, something strange happened.
Here are a few procedures from my unit:
-- Here I declare the thread, and start it
procedure TMainForm.Button9Click(Sender: TObject);
var
thread : TMessageThread;
begin
thread := TMessageThread.Create(true);
thread.FreeOnTerminate := True;
thread.OnTerminate := TMessageThreadTerminate;
thread.Execute;
end;
-- After the thread has terminated, it should say so
procedure TMainForm.TMessageThreadTerminate(Sender: TObject);
begin
ShowMessage('Terminated');
end;
-- Override for the execute procedure.
procedure TMessageThread.Execute;
var
i: Integer;
begin
ShowMessage('Start');
for i := 0 to 1000 do
begin
Application.ProcessMessages;
end;
ShowMessage('Stop');
Terminate;
end;
Now, as soon as I click the button, a messagebox pops up (Start),
followed by the stop messagebox a few instants later on. But I never get
the "terminated" message!
This, I don't understand - I've specified the correct procedure (afaikt),
and I've also tried to do a "DoTerminate" instead of a "Terminate", but
to no avail.
Can anybody please explain to me what's going on?
Thank you very much!
PS.
.
- Follow-Ups:
- Re: Why doesn't my thread terminate?
- From: Rob Kennedy
- uRe: Why doesn't my thread terminate?
- From: Skybuck Flying
- Re: Why doesn't my thread terminate?
- Prev by Date: Re: dfsSystemTreeView, where?
- Next by Date: uRe: Why doesn't my thread terminate?
- Previous by thread: Function calling convention for large return values ?
- Next by thread: uRe: Why doesn't my thread terminate?
- Index(es):