Jump to content
RaelB

Question about pipeline progress indicator

Recommended Posts

Hi,

I have a simple pipeline, that takes in a list of 20 items, and has one stage. For each item, the stage waits 1 second, and then sends a message to the main UI, which will add the item to a Memo, and update a ProgressBar.

 

The code is looking like this:

procedure TForm1.AddDownloadItems;
var
  DownloadItem: TDownloadItem;
  I: Integer;
begin
  for I := 0 to 19 do
  begin
    DownloadItem := TDownloadItem.Create;
    DownloadItem.Id := I;
    FDownloadItems.Add(DownloadItem);
  end;
end;

procedure TForm1.Stage1(const input, output: IOmniBlockingCollection; const
  Task: IOmniTask);
var
  Item: TDownloadItem;
  InputItem: TOmniValue;
begin
  for InputItem in Input do
  begin
    Item := TDownloadItem(InputItem.AsObject);
    Sleep(1000);
    Task.Comm.Send(0, Item.Id);
    Output.Add(InputItem);
  end;
end;

procedure TForm1.UpdateProgress(const task: IOmniTaskControl; const msg: TOmniMessage);
begin
  Inc(Progress);
  Memo1.Lines.Add(msg.MsgData.AsString);
  ProgressBar1.Position := Progress;
end;

procedure TForm1.GetDownloadsPipline;
var
  Item: TDownloadItem;
begin
  { ====== Start Pipeline ========= }

  Screen.Cursor := crHourGlass;
  StartTime := GetTickCount;
  FPipeline := Parallel.Pipeline
    .Stage(Stage1, Parallel.TaskConfig.OnMessage(UpdateProgress)).NumTasks(4) //Environment.Process.Affinity.Count)
    .OnStop(
      procedure
      begin
        PostMessage(Form1.Handle, WM_STOPPED, 0, 0);
      end)
    .Run;

  Self.AddDownloadItems;
  for Item in FDownloadItems do
    FPipeline.Input.Add(Item);
  FPipeline.Input.CompleteAdding;
end;

When the program runs, a few items get added to the Memo, and only afterwards the progressbar updates. This seems strange. I would expect the progress bar to update simultaneously with the memo. Please see attached video. Any ideas?

 

Thanks

 

 

 

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
×