Jump to content

Search the Community

Showing results for tags 'ttask'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 4 results

  1. Hello. I'm workin with Delphi 10.4.2 community in Windows 10/11. I've this procedure procedure TfrmMain.AddLog(NomeProc, PointProc, Datis: string; MarckEX: boolean); var ErrorLogFileName : string; ErrorFile : TextFile; markec : string; begin ErrorLogFileName := ExtractFilePath(ParamStr(0))+'error.log'; AssignFile(ErrorFile, ErrorLogFileName) ; if FileExists(ErrorLogFileName) then Append(ErrorFile) else Rewrite(ErrorFile) ; try if MarckEX then begin markec := '***;'; end else begin markec := '---;' end; ErrorData := DateTimeToStr(Now) + ';' + NomeProc + ';' + PointProc + ';' + Datis + ';' + markec; WriteLn(ErrorFile,ErrorData) ; finally CloseFile(ErrorFile) end; end; And I've this Task (simple method to work in another thread) called in a button click TASK := TTask.Create( procedure begin //do some work and then.... call AddLog.. AddLog('Test','Test','Test',false); end ); TASK.Start(); If I call AddLog into TASK do not work. I tried to call AddLog in and out to TASK := TTask.Create( procedure begin //do some work and then.... call AddLog.. TThread.Synchronize(nil, procedure begin AddLog('Test','Test','Test',false); end ); end ); TASK.Start(); but without success, nothing is ever written to the file. What am I doing wrong?
  2. I am using delphi 11.2 in windows Full source attached Either one only run 1 thread,please help me,thanks. ==================================================== procedure TForm1.btnParallelForClick(Sender: TObject); TParallel.For(0,System.CPUCount,procedure(I:Int64) var thinkstep: string; begin MinMax(board,mutiSideisRed,8,thinkstep); end; end); ===================================================== procedure TForm1.btnTTaskClick(Sender: TObject); var tasks: array of ITask; thinkstep : array of string; SW: TStopwatch; a:integer; begin Setlength (tasks ,System.CPUCount); Setlength (thinkstep ,System.CPUCount+1); ReInitboard; SW :=TStopWatch.Create; for a := 0 to System.CPUCount-1 do begin thinkstep[a+1] := ''; tasks[a] := TTask.Create (procedure () begin PMinMax(board,mutiSideisRed,8,thinkstep[a]); end); end; for a := 0 to System.CPUCount-1 do tasks[a].Start; TTask3.zip
  3. Hi all, I'm trying to use TTask to perform some parallel code with Sydney 10.4.1 looking at the sample code in Help System, so it should be supported by 10.4.1: but I've got always the error: [dcc32 Error] osIPCTCPServerContext.pas(423): E2250 There is no overloaded version of 'Create' that can be called with these arguments Have you any idea about it? Thank you in advance for replies.
  4. I need to run a piece of code in TTask threads using a thread pool, that runs in every platform and get the results in the main UI thread in a thread safe message object without checking with a timer. Inspired by a post from Remy Lebeau in the Lazarus forum I wrote the following. Comments, suggestions, errors in the code welcome. interface type TTaskdata < T >= class type mydataP = ^T; mytaskproctyp =procedure(a: mydataP) of object; private Data: T; ProcessData: mytaskproctyp; procedure DoProcess; public procedure queue(datatyp: T; taskproc: mytaskproctyp); end; implementation procedure TTaskdata<T>.queue(datatyp: T; taskproc: mytaskproctyp); begin Data := datatyp; ProcessData := taskproc; TThread.queue(nil, DoProcess); end; procedure TTaskdata<T>.DoProcess; begin ProcessData(@Data); end; In an other/main Tform Unit type Dsoup = record nam: string; i: integer; end; // a sample record for send and receiving data to Ttask routine ReturnProc = procedure(mypointer: Ttaskdata<Dsoup>.mydataP) of object; var FCustomPool: TThreadPool; // the theadpool to be used for reusing threads, it should initialiazed in Tform's constructor procedure TForm1.Button1Click(Sender: TObject); // the initial route that will prepare data for Ttask and run it var soup: Dsoup; begin { set in Dsoup all data to send in TTask routine } TTask.Run(dowork(soup, getresults), FCustomPool); end; function TForm1.dowork(const a: Dsoup; p: ReturnProc): tproc; begin Result := // anonymous function to run by Ttask procedure var ff: Ttaskdata<Dsoup>; begin ff := Ttaskdata<Dsoup>.create; try { do all the task job here } ff.queue(a, p); // add result data to be sent with Thread.queue except ff.free; end; end; end; procedure TForm1.getresults(p: Ttaskdata<Dsoup>.mydataP); begin { here come the results from TTask in the main UI thread } end;
×