Use parallel processing TTaks.
procedure executarrotina;
begin
vg_Tarefas.Add(TTask.Create(procedure ()
var vEmail : TEmail;
begin
vEmail := TEmail.Create;
try
vEmail.Assunto := pAssunto;
vEmail.Destinatarios := pDest;
vEmail.Mensagem := pMens;
vEmail.Enviar;
finally
FreeAndNil(pMens);
FreeAndNil(vEmail);
end;
end));
vg_Tarefas[vg_Tarefas.Count - 1].Start;
end;
declare the variable
var vg_Tarefas : TList<ITask>;
uses System.Generics.Collections;
Very important: Never use commands that display warnings, update edit, in this routine. If you want performance, do not upgrade screen. If you need to update the screen, update something in a table and trigger event in the bank, it will be more efficient.
In this example, I am sending email in the background.