Jump to content
alr1976

Ttask loop each 1 second

Recommended Posts

Hi!

 

I Need to run a task each 1 second but i Need to pass a variable First Time. It Is possible? How ? Can you do male a small example?

Thanks

 

PS i buy your last book. Next week i Will riceive It.

Share this post


Link to post
  FWorker := TWorker.Create(SpinEdit1.Value);

  FTimedTask :=
    Parallel.TimedTask .Every(1000)
      .Execute(
        procedure (const task: IOmniTask)
        var
          value: integer;
        begin
          FWorker.Tick;
          value := FWorker.Value;
          task.Invoke(
            procedure
            begin
              ListBox1.Items.Add(value.ToString);
            end);
        end);

  FTimedTask.Start;

type
  TWorker = class
  strict private
    FValue: integer;
  public
    constructor Create(startAt: integer);
    procedure Tick;
    property Value: integer read FValue;
  end;

constructor TWorker.Create(startAt: integer);
begin
  inherited Create;
  FValue := startAt;
end;

procedure TWorker.Tick;
begin
  Inc(FValue);
end;

 

Source: https://gist.github.com/gabr42/15a514a2960be43a0a5b1a6db69274f7

 

  • Like 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×