Call to EndThread after Execute method has finished never returns

78 views
Skip to first unread message

ChrisStoyles

unread,
Jan 13, 2011, 7:16:49 PM1/13/11
to
I'm having the strangest problem:

In the "Classes" unit there is the following callback which is called
when a a TThread's Execute method is finished running:

function ThreadProc(Thread: TThread): Integer;
var
FreeThread: Boolean;
begin
try
Thread.Execute;
finally
FreeThread := Thread.FFreeOnTerminate;
Result := Thread.FReturnValue;
Thread.FFinished := True;
Thread.DoTerminate;
if FreeThread then Thread.Free;
EndThread(Result);
end;
end;


The call to EndThread(Result) just sits there and never returns. This
even happens if I have no code in my Execute method (i.e. the thread
completes immediately after start up). This is how I start my thread:

if (not Assigned(m_Events)) then
m_Events := CLicenseServiceEvents.Create(true, appName);

m_Events.FreeOnTerminate := true;
m_Events.Resume;

I stop it like this:

m_Events.Terminate;
m_Events.WaitFor;

Does anybody know why this system call to EndThread would just freeze
like that?

Thanks,
Chris.

Reply all
Reply to author
Forward
0 new messages