How to start/stop a monitoring Delphi thread on demand?

前端 未结 3 1639
有刺的猬
有刺的猬 2021-01-01 08:11

I\'ve been looking for a way to monitor for specific registry changes in Delphi. Found a solution at about.com:

procedure TRegMonitorThread.Execute;
begin
           


        
3条回答
  •  无人及你
    2021-01-01 08:36

    This works, just make small changes as below and now when you call Terminate:

      TRegMonitorThread = class(TThread)
      ...
      public
        procedure Terminate; reintroduce;
    ...
    
    procedure TRegMonitorThread. Terminate;  // add new public procedure
    begin
      inherited Terminate;
      Windows.SetEvent(FEvent);
    end;
    
    procedure TRegMonitorThread.Execute;
    begin
      InitThread;
    
      while not Terminated do
      begin
        if WaitForSingleObject(FEvent, INFINITE) = WAIT_OBJECT_0 then
        begin
          if Terminated then // <- add this 2 lines
            Exit;
          ...
        end;
      end;
    end;
    

提交回复
热议问题