How can I kill task on Demand? When i do this:
CreateTask(TWorker.Create())
.Invoke(@TWorker.Execute)
.MonitorWith(FEventMonitor)
.SetParameter('ThreadID',i)
.Join(FWorkers)
.WithLock(FLockToken).Schedule(GlobalOmniThreadPool).WaitFor(0);
if Assigned(FWorkers) then begin
// FWorkers.TerminateAll; freeze
FWorkers.TerminateAll(0); // freeze
FWorkers:=nil;
GlobalOmniThreadPool.CancelAll;
Log('All tasks stopped',Form1.Memo1);
end
else begin
Log('Nothing to stop',Form1.Memo1);
end;
The main application freezes. It doesn't really matter whether, do I run it outside or inside the debugger even if there is only 1 task running.
Because I don't want to put this code 30 times in the task. Frustrating for the users and programers.
If GlobalCancel=true then
Task.Terminate;
There should be a way to do this globally without this.