Delphi correct use of tasks
<p><strong>SITUATION</strong></p>

<p>To better understand the PPL and how a <code>Task</code> works I tried to make a very easy program in which, once you have clicked a button, a <code>ListBox</code> is filled with a list of directories in the disk.</p>

<pre><code>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;
</code></pre>

<p>The folder <code>maths</code> you can see above is not very huge and the task takes about 3 seconds to execute. The task is declared as follows:</p>

<pre><code>type
  TForm3 = class(TForm)
    ListBox1: TListBox;
    //... other published things var ...
  private
    proc: ITask;
  public
    //... public var ...
  end;
</code></pre>

<hr>

<p><strong>PROBLEM</strong></p>

<p>When I work (for example) with <code>C:\Users\albertoWinVM\Documents</code> I have a very big amount of folders and the program takes up to 3 minutes before filling the ListBox. </p>

<p>If I closed the program (while the task is still running) having only the code above, from what I have understood reading online, the task will still run until he hasn't finished. Am I correct?</p>

<pre><code>procedure TForm3.FormDestroy(Sender: TObject);
begin
 proc.Cancel;
end;
</code></pre>

<p>I thought that I could add this code to improve the safety of the program. Is that enough?</p>