DELPHI中怎样正确的关闭一个线程
1个回答
展开全部
unitUnit1;interfaceusesWinapi.Windows,Winapi.Messages,System.SysUtils,System.Variants,System.Classes,Vcl.Graphics,Vcl.Controls,Vcl.Forms,Vcl.Dialogs,Vcl.StdCtrls;typeTForm1=class(TForm)btnStart:TButton;Memo1:TMemo;procedurebtnStartClick(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;TTestThread=class(TThread)privateAnswer:Integer;protectedprocedureGiveAnswer;procedureExecute;override;end;varForm1:TForm1;implementation{$R*.dfm}procedureTForm1.btnStartClick(Sender:TObject);vart1,t2:TTestThread;begint1:=TTestThread.Create;t2:=TTEstThread.Create;end;{TTestThread}procedureTTestThread.Execute;vari:Integer;begininherited;FreeOnTerminate:=True;Answer:=0;fori:=1to20dobeginInc(Answer);ifTerminatedthenbreak;Synchronize(GiveAnswer);end;end;procedureTTestThread.GiveAnswer;beginForm1.Memo1.Lines.Add(IntToStr(Answer));end;end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询