Execute background routines

0

I have a routine to run when opening my system once a day, I put a panel with a message for the client to see that it is being processed, but now it is taking a lot of time to run.

My idea is to put in background , I tried Thread but it crashes my system.

What is the best way to do this without having to crash the user?

    
asked by anonymous 07.05.2016 / 14:53

1 answer

0

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.

    
09.05.2016 / 15:55