delphi Delphi TParallel Cleanup Needed用法


本文整理自网络,侵删。

 

TParallel创建的任务/线程或多或少是持久性的,这可能有利于重用。但是,我希望看到一个用于清理的类方法。

 

TParallel.For(0, 20, (procedure(A : integer) begin writeln(A) end));

 uses

  System.Diagnostics,

  System.Threading;

 

上面的代码留下了线程,可以在任务管理器中观察到。

 

创建自己的TThreadPool实例并在不再需要时处置它会令您满意吗?

var

  Pool: TThreadPool;

begin

  Pool := TThreadPool.Create;

  try

    TParallel.For(0, 20, (procedure(A : integer) begin writeln(A) end), Pool);

    Write('Disposing of the thread pool - press ENTER to continue...');

  finally

    Pool.DisposeOf;

  end;

end;

线程池仍然存在,可以有效地重用。当需要显式管理线程时,建议使用TThreadpool。

相关阅读 >>

Delphi 首字母转换大写

Delphi hex 相关单元

Delphi 中 unicode 转汉字 函数

Delphi关于tjpegimage的使用(bmp\ jpg格式转换)

Delphi cxgrid应用笔记

Delphi 判断tcp端口是否被占用的方法

Delphi 从其它access数据导入数据到本地数据库

Delphi uhttp_flood

Delphi xe6调用android手机标准功能

Delphi整理三(窗体和基本组件)

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...