OTL - 按需杀死任务

时间:2012-12-08 21:00:04

标签: delphi delphi-xe2 omnithreadlibrary

如何按需杀死任务?当我这样做时:

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;

主要应用程序冻结。我是否在户外运行并不重要 或者在调试器内,即使只有一个任务在运行。

因为我不想将此代码放在任务中30次。对用户和程序员感到沮丧。

If GlobalCancel=true then
Task.Terminate;

如果没有这个,应该有一种全球化的方法。

0 个答案:

没有答案
相关问题