小编Dan*_*Dan的帖子

为什么OmniThreadLibrary的ForEach阻塞主线程?

使用OmniThreadLibrary和Delphi XE4,我希望运行多个在后台处理数据的线程,为我现有的代码增加速度.

调用下面的过程时,Application GUI将停止处理任何输入,直到所有线程都完成为止.我的理解是,.NoWait即使线程正在运行,using也应允许该过程退出.

procedure Test(input: TStringList; output: TList<TMaintFore>);
var
  outQueue: IOmniBlockingCollection;
  transaction: TOmniValue;
begin
  outQueue := TOmniBlockingCollection.Create;
  Parallel.ForEach(0, input.Count - 1)
    .NoWait
    .Into(outQueue)
    .Execute(
      procedure(const value: integer; var result: TOmniValue)
      begin
        result := TMaintFore.Create(input[value]);
      end
    );
end;
Run Code Online (Sandbox Code Playgroud)

我对ForEach循环的理解是否不正确,建议我应该使用替代方法来实现后台处理?任何关于正确使用OmniThreadLibrary的建议都表示赞赏.

delphi omnithreadlibrary delphi-xe4

2
推荐指数
1
解决办法
1207
查看次数

标签 统计

delphi ×1

delphi-xe4 ×1

omnithreadlibrary ×1