I am using KillThreadList: TList global. I track it in my thread as:
while (Not Terminated) do begin inc(Inker); if (WaitForSingleObject(FTick, finterval) = WAIT_TIMEOUT) then Begin if Inker >= 10 then Begin ProcessTables; Inker := 0; sleep(1000); End; if KillThreadList.Contains(ThreadID) = True then Terminate; End; end;
I also test KillThreadList in my processes to allow me to drop them before completion, where it is safe.
I pass the OnTerminate event to the Main thread and remove the ThreadID from the KillList. I use this model extensively and it has not failed me yet.
procedure TfrmProcessQualcommLocations.OnTerminateThread; var ThreadID : Cardinal; i : integer; aStatusBar :TStatFrame; begin ThreadID := (Sender as Tthread).ThreadID; for i := 0 to StatusBarList.Count -1 do Begin if StatusBarList.Items[i].ThreadID = ThreadID then Begin aStatusBar := StatusBarList.Items[i]; KillThreadList.Extract(ThreadID); StatusBarList.Extract(aStatusBar); aStatusBar.Free; break; End; End; self.Refresh; end;
In the above case, I also remove some GUI elements.
Hope this helps. SpringerRider
Meta mussel
source share