同上急!!!!!

解决方案 »

  1.   


    unit MyTestThread;interfaceuses
      Classes,SyncObjs;type
      TMyThread = class(TThread)
      private
        //定义内部对象
        FInterval:Integer;
        { Private declarations }
      protected
        procedure Execute; override;
      public
        constructor Create(CreateSuspend: Boolean);
        destructor  Destroy; override;
        property    Interval:Integer read FInterval write FInterval;
      end;
       procedure   NotifyThreadsToQuit;var
      QuitEvent: TEvent;implementationconstructor TMyThread.Create(CreateSuspend: Boolean);
    begin
      inherited;
      //创建线程对象
    end;destructor TMyThread.Destroy;
    begin
      //析构线程对象
      inherited;
    end;procedure TMyThread.Execute;
    begin
      while not Terminated do
      begin
        //do the procedure;
        case QuitEvent.WaitFor(Interval) of
          wrSignaled, wrAbandoned: Terminate;
          wrTimeOut, wrError: ; // do nothing
        end;
      end;  { Place thread code here }
    end;procedure NotifyThreadsToQuit;
    begin
      QuitEvent.SetEvent;
    end;initialization
      QuitEvent := TEvent.Create(nil,True,False,'ThreadQuitEvent');finalization
      QuitEvent.Free;end.
    界面程序只要Use该单元,且执行NotifyThreadsToQuit即可!
      

  2.   

    另:Interval为间隔轮询时间!
      

  3.   


    //客户端调用线程;
    var
      MyThread:TMyThread;
    begin
      MyThread:=TMythread.Create(True);
      MyThread.FreeOnTerminate:=False;
      MyThread.Interval:=1000//Interval为毫秒级的;
      MyThread.Resume;
    end;
    //客户端终止线程
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      NotifyThreadsToQuit
    end;