为什么我不能运行两次或更多次我的线程?

时间:2015-10-13 12:54:52

标签: multithreading lazarus freepascal

为什么我不能运行两次或更多次我的线程。 (代码中的第二个调用不起作用)。在程序"执行"没有循环,表现得好像一直在工作。

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;    
}

端;

1 个答案:

答案 0 :(得分:0)

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