//百度上找到的: if Assigned(Mythreadtask) then begin if Mythreadtask.Status = TTaskStatus.Running then begin //If it is already running don't start it again Exit; end; end; Mythreadtask := TTask.Create (procedure () begin ClientModule1.Fc_Server_SM_FmClient.RemoPrint(billvchcode); end); Mythreadtask.Start; 对于App 执行时间较长的任务总是闪退的情况,的确有帮助, 但是我是想请教一下: 多线程只需要.start,不需要释放? 请给一些关于Android 下多线程的讲解,谢谢!!!
----------------------------------------------
偶尔做做代码应付一下工作,却发现Delphi已成必配
procedure xxxRun_My_Tasks; begin TTask.Run( { each task on parallel way... out main-thread } procedure begin for var T in MyTasks do if (T<>nil) and not(T.Status = TTaskStatus.Running {...}) then T.start; // running all... end); end;
function xxxMyTaks_Is_Running:boolean; begin result := false; // // TTaskStatus.Running, TTaskStatus.WaitingForRun, etc.... // for var T in MyTasks do if (T<>nil) and (T.Status = TTaskStatus.Running {...}) then exit( true ); // some is running? end;
procedure xxxMy_Tasks_Is_Running_Try_Cancel; var i,x:integer; begin i := length( MyTasks ); x := 0; // for var T in MyTasks do begin if (T<>nil) and (T.Status = TTaskStatus.Running {...}) then begin T.Cancel; // take a delay time to cancel it... it's not security here!!!! it can fail... x := x + 1; end; end; // sleep( 100 ); // a time... // if (i > 0) and (x = i) then MyTasks := []; end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3