前言
bg 与 ui 是互相嵌套的,没有终点;就是说 程序 若是高密计算,ui + bg 一切同时并行,快速响应;
示例代码
unit main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, doroutine, Vcl.ComCtrls;
type
TFormMain = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
end;
var
FormMain: TFormMain;
implementation
{$R *.dfm}
procedure ui1(task: TTask);
begin
FormMain.ProgressBar1.Position := task.getInteger('i');
end;
procedure bg1(task: TTask);
begin
//doSomeThing http 请求了,或其他 后台业务,bg线程 衍生 100个 待主线程执行的协程
for var i := 1 to 100 do
begin
task.ui(ui1).data('i', i).start;
end;
end;
procedure TFormMain.Button1Click(Sender: TObject);
begin
task.bg(bg1).start;
end;
end.