1、我知道TMsgThread.Create(True)这样可以创建一个线程,如果参数为true,线程创建但不执行。
否则,如果是false,创建并且执行线程。
2、FreeOnTerminate:=true;线程执行完毕以后就自动释放了
3、线程创建很消耗资源。所以如果定时要执行线程的代码,就不要把它释放。基于以上的考虑,我对下面的代码是这样使用的。{线程类定义}
TMsgThread = class(TThread)
private
{ Private declarations }
procedure ShowInMemo;
protected
procedure Execute; override;
public
end;procedure TWeather.Execute;
begin
{ Place thread code here }
FreeOnTerminate:=false;//不释放
Synchronize(ShowInMemo);
end;{主程序}
var
newThrd:TMsgThread;procedure TForm1.Button1Click(Sender: TObject);
begin
newThrd:=TMsgThread.Create(True);
with newThrd do
begin
Resume;
end;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin newThrd.free; //主窗体关闭的时候释放线程对象
end;===================================
高手们,如上处理代码,应该符合规范吧。
否则,如果是false,创建并且执行线程。
2、FreeOnTerminate:=true;线程执行完毕以后就自动释放了
3、线程创建很消耗资源。所以如果定时要执行线程的代码,就不要把它释放。基于以上的考虑,我对下面的代码是这样使用的。{线程类定义}
TMsgThread = class(TThread)
private
{ Private declarations }
procedure ShowInMemo;
protected
procedure Execute; override;
public
end;procedure TWeather.Execute;
begin
{ Place thread code here }
FreeOnTerminate:=false;//不释放
Synchronize(ShowInMemo);
end;{主程序}
var
newThrd:TMsgThread;procedure TForm1.Button1Click(Sender: TObject);
begin
newThrd:=TMsgThread.Create(True);
with newThrd do
begin
Resume;
end;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin newThrd.free; //主窗体关闭的时候释放线程对象
end;===================================
高手们,如上处理代码,应该符合规范吧。
myThrd:=TmyThrd.crate(ture);我用语句myThrd.resume;程序关闭的时候,销毁对象myThrd.free;那我在程序运行期间,如果要定时的运行这个线程,如何作啊。执行这个myThrd.resume;有没有用