I think you should show your reboot code? Since, as I know, if a thread completes the Execute procedure, the state in the OS will change to DONE, and the resume call will start this thread again only as a function in the main thread, and not in a separate thread.
since you can use this sample code for your needs
unit UWorker; interface uses Windows, Classes, Contnrs; type TWorkerThread=class; TWorkerJob=class procedure ExecuteJob(Worker: TWorkerThread); virtual; abstract; end; TWorkerThread=class(TThread) private FFinished: TObjectList; FNotFinished: TObjectList; protected procedure Execute;Override; public constructor Create(createSuspended: Boolean);override; destructor Destroy; override; public property Finished: TObjectList read FFinished; property NotFinished: TObjectList read FNotFinished; end; implementation { TWorkerThread } constructor TWorkerThread.Create(createSuspended: Boolean); begin inherited; FFinished := TObjectList.Create; FNotFinished := TObjectList.Create; end; destructor TWorkerThread.Destroy; begin FFinished.Free; FNotFinished.Free; inherited; end; procedure TWorkerThread.Execute; var CurrentJob: TWorkerJob; begin while not Terminated do begin if FNotFinished.Count > 0 then begin CurrentJob := TWorkerJob(FNotFinished.Items[0]); FNotFinished.Extract(CurrentJob); with CurrentJob do begin ExecuteJob(Self); end; FFinished.Add(CurrentJob); end else begin // pass the cpu to next thread or process Sleep(5); end; end; end; end.
To use this code, simply create a worker, and then create an instance of the tasks and add them to the NotFinished list. The employee will complete all the tasks one by one. To restart a task, simply extract it from the Ready List and add it again to NotFinished.
remember that you must inherit your tasks and override the ExecuteJob procedure.
Mahdi source share