Multithreading 为什么我不能运行两次或两次以上的线程?

Multithreading 为什么我不能运行两次或两次以上的线程?,multithreading,lazarus,freepascal,Multithreading,Lazarus,Freepascal,为什么我不能运行两次或两次以上的线程。(代码中的第二个调用不起作用)。在“Execute”过程中没有循环,其行为就像一直在工作一样 procedure TMyThread.Execute; begin do_something(); end; procedure TForm1.Do; var DrawerA:TMyThread; begin DrawerA:=TMyThread.Create(True); DrawerA.Priority:=tpNormal; DrawerA.Fr

为什么我不能运行两次或两次以上的线程。(代码中的第二个调用不起作用)。在“Execute”过程中没有循环,其行为就像一直在工作一样

procedure TMyThread.Execute;
begin  
do_something();
end;


procedure TForm1.Do;
var DrawerA:TMyThread;
begin

DrawerA:=TMyThread.Create(True); 
DrawerA.Priority:=tpNormal; 
DrawerA.FreeOnTerminate:=False;           


DrawerA.Start;
DrawerA.WaitFor;


DrawerA.Start;
DrawerA.WaitFor;

{
if( Not DrawerA.Suspended) then DrawerA.Start
else DrawerA.Resume;    
}

结束

线程执行其线程过程,然后终止。如果希望线程执行多个任务,则需要将迭代构建到线程过程中。

线程执行其线程过程,然后终止。如果希望线程执行多个任务,则需要将迭代构建到线程过程中。

“代码中的第二个调用不起作用”-是否收到异常?您面临的具体错误行为是什么?在运行Execute方法中的所有代码后,您的线程无法重新启动。您必须释放并创建所需线程类型的另一个实例。通常包括但不终止do begin。。。结束Execute方法中的代码,以便在不必重新创建线程的情况下多次使用线程。您可以回答自己的问题并接受它。“代码中的第二个调用不起作用”-您是否收到异常?您面临的具体错误行为是什么?在运行Execute方法中的所有代码后,您的线程无法重新启动。您必须释放并创建所需线程类型的另一个实例。通常包括但不终止do begin。。。结束Execute方法中的代码,以便在不必重新创建线程的情况下多次使用线程。您可以回答自己的问题并接受它。