为什么我讲线程实例suspend后,代码执行不到 form1.Edit2.Text:=str+' ends'; LeaveCriticalSection(c);这里呢......
tthread执行了suspend就会直接退出了吗????procedure Ta.Execute;
var i:integer;
begin
{ Place thread code here }
EnterCriticalSection(c);
try
form1.Edit2.Text:=str+' begins';
while not suspended do
begin
form1.label1.caption:=str;
i:=StrToInt(form1.Edit1.text);
inc(i);
form1.setCount(i);
Sleep(1000);
end
finally
form1.Edit2.Text:=str+' ends';
LeaveCriticalSection(c);
end;
end;
tthread执行了suspend就会直接退出了吗????procedure Ta.Execute;
var i:integer;
begin
{ Place thread code here }
EnterCriticalSection(c);
try
form1.Edit2.Text:=str+' begins';
while not suspended do
begin
form1.label1.caption:=str;
i:=StrToInt(form1.Edit1.text);
inc(i);
form1.setCount(i);
Sleep(1000);
end
finally
form1.Edit2.Text:=str+' ends';
LeaveCriticalSection(c);
end;
end;
form1.Edit2.Text:=str+' begins';
你应该用Synchronize同步函数.Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure TMyThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
不是suspend后,线程都给挂起了,如何还能执行execute里面的代码