ich will mit dem Thread.Onterminate Event einen Zähler herunterzählen und dann diesen Wert in der UI ausgeben ....
Delphi-Quellcode:
procedure TThreadMainClass.ThreadTerminateInfo(Sender: TObject);
var
FCriticalSection: TCriticalSection;
begin
FCriticalSection := TCriticalSection.Create;
try
FCriticalSection.Enter;
g_RunningThreads := g_RunningThreads - 1;
memo1.lines.add (0, ' number of still running threads' + IntToStr(g_RunningThreads));
FCriticalSection.Leave;
finally
FCriticalSection.Free;
end;
end;
procedure TRoutingClass.executeRouting;
var
.......
_Threads: array of TMyThread;
_hArr: Array of THandle;
rWait: Cardinal;
begin
if g_threadCount > 1 then
begin
setlength(_Threads, g_threadCount);
setlength(_hArr, g_threadCount);
.......
for i := 1 to g_threadCount do
begin
_Threads[i - 1] := TMyThread.Create( ....);
_Threads[i - 1].FreeOnTerminate := true;
_Threads[i - 1].OnTerminate := ThreadTerminateInfo;
_Threads[i - 1].Start;
_hArr[i - 1] := _Threads[i - 1].Handle;
end;
WaitForMultipleObjects(g_threadCount, Pointer(_hArr), true, INFINITE);
// hier bleibt mein Programm in einem DEADLOCK ? stehen ohne
// Free On terminate hat es funktioniert :-(
//