在执行我的OTL多线程程序期间,UI冻结。使用1到16个线程进行测试,UI在过程开始后立即冻结。
Parallel.ForEach(0, CalcList.Count-1)
.NumTasks(nMax)
.NoWait
.Execute(
procedure(const value: integer)
begin
CalcUnit.EntrySearch(value);
end)所有线程消息都会被OmniEventMonitor正确接收。当所有线程都关闭时,OmniEventMonitor一次处理所有收到的消息。我如何确定冻结的原因以找到解决方案。OmnitEventMonitorTaskMessage中的Application.ProcessMessages和/或OmniTED.ProcessMessages没有影响。
对于MCVE:在mainform上:
procedure TForm1.Button1Click(Sender: TObject);
begin
Parallel.ForEach(0, 1)
.Execute(
procedure(const value: integer)
begin
CalcUnit.EntrySearch;
end);
end;在CalcUnit上
procedure EntrySearch;
var
I : integer ;
begin
for I := 1 to 10 do begin
MessageBeep(MB_ICONEXCLAMATION);
Sleep(1000) ;
end;
end;在CalcUnit完成之前,MainForm会冻结。
发布于 2014-11-26 15:53:20
应用程序UI冻结,因为它正在等待所有线程都已完成。我不得不在任务完成时销毁ForEach接口。使用MainForm中的OnStop方法销毁最后一个线程。查看:Incrementing Progress Bar from a ForEach Loop
{Private declarations}
FWorker : IOmniParallelLoop<integer>;
FWorker := Parallel.ForEach(0, CalcList.Count-1)
.TaskConfig(Parallel.TaskConfig.OnMessage(Self))
.NumTasks(nMax)
.NoWait
.OnStop(procedure (const task: IOmniTask)
begin
task.Invoke(procedure begin
FWorker := nil;
end);
end);
FWorker
.Execute(
procedure (const value: integer)
begin
CalcUnit.EntrySearch(value);
end);https://stackoverflow.com/questions/27082455
复制相似问题