What is the correct way to break a thread in Delphi?

1

I am creating a thread with the basic information and structure, as indicated below. Apparently everything is working fine, but I noticed that when running Terminate , the thread does not pass Destroy . Putting a breakpoint from Destroy I noticed that the thread will only end effectively when the main application finishes too. I'm testing on Android and my version of Delphi is 10.2.

BASIC THREAD

// MyThread "TPoolingThread"
constructor TPoolingThread.Create;
begin
   inherited Create(True); // Inicialização suspensa

   // Inicializa algumas coisas
end;

destructor TPoolingThread.Destroy;
begin
   inherited Destroy;
end;

procedure TPoolingThread.Execute;
begin
   try
      while (not Terminated) do begin
         sleep(100);
         // faz algumas coisas
      end;
   finally
      if not Terminated then
         Terminate;
   end;
end;

RUNNING THREAD

// Na aplicação principal.... 

   //////////////////////////////////////////
   // Crio e inicializo a thread no BOTÃO 1
   MyThread := TPoolingThread.Create;
   MyThread.Start;

   //////////////////////////////////////////
   // Interrompo a thread no BOTÃO 2
   MyThread.Terminate;
    
asked by anonymous 17.12.2017 / 15:46

0 answers