delphi 重复执行 协程;doroutine - repeat

代码示例

重复执行的协程是【智能】,是上一次任务【完成后】,间隔 x 毫秒执行下一次任务;

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, System.Skia,
  Vcl.Skia;

type
  TFormMain = class(TForm)
    Memo1: TMemo;
    button1: TButton;
    SkLabel1: TSkLabel;
    procedure button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure helloWorld(go: TGo);
  end;

var
  FormMain: TFormMain;

implementation

{$R *.dfm}

procedure TFormMain.FormCreate(Sender: TObject);
begin
  ReportMemoryLeaksOnShutdown := True;
end;

procedure TFormMain.helloWorld(go: TGo);
begin
  Memo1.Lines.Add(Format('hello world,线程ID: %s', [TThread.Current.ThreadID.ToString]));
end;

procedure helloWorld2(go: TGo);
begin
  OutputDebugString(PChar(Format('hello world,线程ID: %s', [TThread.Current.ThreadID.ToString])));
end;

procedure TFormMain.button1Click(Sender: TObject);
begin
  Memo1.Lines.Add(Format('当前主线程的ID:%s', [TThread.Current.ThreadID.ToString]));
  gt.ui(helloWorld).interval(1000).start;
  gt.bg(helloWorld2).interval(1000).start;
end;

end.

效果图

image

posted @ 2025-02-05 14:15  殴阳疯  阅读(99)  评论(0)    收藏  举报