Jump to content
Sign in to follow this  
PatV

Question about Parallel.ASync

Recommended Posts

Hi All,

 

I'm using Parallel.Async to send an email, even if it's working, I would like to know if my  approach is correct ;

procedure TTFrmPanelPrint.SendMailParallel;
var
  sRacine : string;
  sFrom,sName,sSubject,sBody : string;
begin

  sRacine:=TPath.Combine(FReport.Directory ,FReport.FileName);
  sFrom := rUser(FReport.Print.Values[pspUser]^).Mail.GetMail;
  sName := rUser(FReport.Print.Values[pspUser]^).Name.FirstLastName;
  sBody  :=Comment.Lines.Text;

  sSubject:= FFile.External;
  end;

    Parallel.Async
    (
      Procedure(const task : IOmniTask)
        function AddAttach(const aRacine : string) : TStringList;
        var
          sFile : string;
        begin
          Result:=TStringList.Create;
          Result.Add(aRacine+cExtPdf);
          Result.Add(aRacine+cExtXlsx);
          for sFile in LBAttachments.Items
            do Result.Add(sFile);
        end;
      var
        sAttach,sTo,sBC,sCC : TSTringList;
      begin

        sAttach := AddAttach(sRacine);

        sTo     :=TStringList.Create;
        sCC     :=TStringList.Create;
        sBC     :=TStringList.Create;

        sTo.Add(CbCommunication.Text);

        Task.Invoke
        (
         procedure
         begin
          FMail.WithFrom(sFrom)
               .WithFromName(sName)
               .WithTo(sTo)
               .WithSubject(sSubject)
               .WithBody(sBody)
               .WithAttachments(sAttach)
               .WithPrcMailLog(LogAdd)
               .WithPrcOnDone(MailSendDone)
               .Send;
          sTo.Free;
          sCC.Free;
          sBC.Free;
          sAttach.Free;
         end
        )
      end
    );
end;

Thanks a lot

 

Patrick

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×