SITUATION
To better understand PPL and how it works Task, I tried to make a very light program in which, after clicking a button, it is ListBoxfilled with a list of directories on the disk.
procedure TForm3.Button1Click(Sender: TObject);
var proc: ITask;
begin
//Show that something is going to happen
Button1.Caption := 'Process...';
proc := TTask.Create(
procedure
var strPath: string;
sl: TStringDynArray;
begin
if (DirectoryExists('C:\Users\albertoWinVM\Documents\uni\maths')) then
begin
ListBox1.Items.Clear;
sl := TDirectory.GetDirectories('C:\Users\albertoWinVM\Documents\uni\maths',
TSearchOption.soAllDirectories, nil);
for strPath in sl do
begin
ListBox1.Items.Add(strPath);
end;
//At the end of the task, I restore the original caption of the button
Button1.Caption := 'Go';
Label1.Caption := 'Finished';
end;
end
);
proc.Start;
end;
The folder mathsthat you see above is not very large, and the task takes about 3 seconds. The task is declared as follows:
type
TForm3 = class(TForm)
ListBox1: TListBox;
private
proc: ITask;
public
end;
PROBLEM
When I work (for example) with C:\Users\albertoWinVM\Documents, I have a very large number of folders, and the program takes up to 3 minutes before filling out the ListBox.
If I closed the program (while the task is still running), having only the code above, from what I understood as reading on the Internet, the task will be executed until it finishes. Am I right?
procedure TForm3.FormDestroy(Sender: TObject);
begin
proc.Cancel;
end;
, . ?