T
the_best_of_bes
Unregistered / Unconfirmed
GUEST, unregistred user!
我的一个线程的简单的程序,为什么在创建后挂起,第一次唤醒时可以执行Execute中的内容,但以后再唤醒时就不能执行Execute中的内容了。
{线程}
TTHtest=class(TTHread)
private
protected
public
constructor Create(CreateSuspended: Boolean);
procedure Execute;override;
end;
implementation
constructor TTHtest.Create(CreateSuspended: Boolean);
begin
inherited create(createsuspended);
freeonterminate:=false;
test:='';//全局变量test:string
end;
procedure TTHtest.Execute;
begin
inherited;
test:=test+'aaa';//全局变量test:string
Suspend;
end;
{创建调用}
procedure TFMainSock.Button10Click(Sender: TObject);
begin
thtest:=TTHtest.Create(true);//全局变量thtest:TTHtest
end;
procedure TFMainSock.Button12Click(Sender: TObject);
begin
if thtest.Suspended then
thtest.Resume;//第一次执行Execute中的内容,以后不执行Execute中的内容
end;
{线程}
TTHtest=class(TTHread)
private
protected
public
constructor Create(CreateSuspended: Boolean);
procedure Execute;override;
end;
implementation
constructor TTHtest.Create(CreateSuspended: Boolean);
begin
inherited create(createsuspended);
freeonterminate:=false;
test:='';//全局变量test:string
end;
procedure TTHtest.Execute;
begin
inherited;
test:=test+'aaa';//全局变量test:string
Suspend;
end;
{创建调用}
procedure TFMainSock.Button10Click(Sender: TObject);
begin
thtest:=TTHtest.Create(true);//全局变量thtest:TTHtest
end;
procedure TFMainSock.Button12Click(Sender: TObject);
begin
if thtest.Suspended then
thtest.Resume;//第一次执行Execute中的内容,以后不执行Execute中的内容
end;