Jump to content
PatV

way to send an object to the main thread from task

Recommended Posts

Delphi 10.3

Omnithead 3.07.5

 

Hi all,

 

I'm testing and playing with the sample 24_ConnectionPool, so in the main form I've added

 

procedure TfrmConnectionPoolDemo.btnScheduleClick(Sender: TObject);

var
  i : integer;
  Params  : TParameters;

begin

 WithParamsReset(Params);
 WithParam(Params,cDteFrom,'2019/01/01',dtString);

 WithParam(Params,cDteTo  ,'2019/09/01',dtString);
 

 for i:=0 to 99 do    // for testing purpose launch 100 task

 begin
    Log(Format('Creating task %d',));
    CreateTask(Worker,format('%0.2d',))
      .MonitorWith(OTLMonitor)
      .SetParameter('Params',TOmniValue.FromArray<rParameter>(Params))
      .SetParameter('ProcName','prc_ProcedureToCall')
      .Schedule(FConnectionPool); 

 end;
end;

 

now my question is ;

 

how can I retreive the result of the data connection in an object and send it from task Worker to the main thread ?

 

I was thinking about msg.msgData  from IOmniMessage  and retreive it through OTLMonitor  or insert a TOmniTaskInvokeFunction  into my Worker task

 

What is the best way ?

 

Thanks 

 

Patrick

 

 

 

 

 

 

 

 

Share this post


Link to post

Just use any of the mechanisms for sending data to the main thread (Task.Comm.Send, Task.Invoke).

 

Or standard Delphi mechanisms (TThread.Queue).

 

Or am I missing something?

 

Edited by Primož Gabrijelčič

Share this post


Link to post

Thanks again Primoz for your fast answer, I'll go with task.Comm.Send 

 

Regards

 

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
×