关于多线程控制的一些问题
为什么暂停线程时还是会执行的,不会暂停,,刚开始接触线程,不太懂,请大家指定一下,
procedure TTestThread.Execute;
begin
self.FreeOnTerminate := True;
Synchronize(SetValue);
end;
procedure TTestThread.SetValue;
var
i: Integer;
begin
for i := 0 to 100000 do
begin
Application.ProcessMessages;
if self.Terminated then Break;
form1.Edit1.Text := IntToStr(i);
end;
end;
//开始线程
procedure TForm1.Button1Click(Sender: TObject);
begin
MyThread := TTestThread.Create(True);
mythread.Resume;
end;
//暂停线程
procedure TForm1.Button2Click(Sender: TObject);
begin
MyThread.Suspend;
end;
//终止线程
procedure TForm1.Button3Click(Sender: TObject);
begin
MyThread.Terminate;
end;
//继续执行线程
procedure TForm1.Button4Click(Sender: TObject);
begin
MyThread.Resume;
end;