processmonitor.~pas

来自「Monitoring Directory Changes」· ~PAS 代码 · 共 78 行

~PAS
78
字号
unit ProcessMonitor;

interface

uses
  Classes,Windows,SysUtils;

type
  TProcessMonitor = class(TThread)
  private
    { Private declarations }
  protected
    FProRef: TComponent;
    procedure Execute; override;
    procedure SendEvent;
  public
    FHandle: integer;
    constructor Create(ProRef: TComponent); overload;
  end;

implementation

{ TMonitor }

uses DirMonitor;

constructor TProcessMonitor.Create(ProRef: TComponent);
begin
  self.Create(true);
  self.FProRef:=ProRef;
  FreeOnTerminate:=true;
  self.Priority:=tpTimeCritical;
end;

procedure TProcessMonitor.SendEvent;
var ProcesoPrin: TDirMonitor;
begin
  ProcesoPrin:=self.FProRef as TDirMonitor;
  ProcesoPrin.RecibirEvento;
end;

procedure TProcessMonitor.Execute;
var state:cardinal;
  quit:boolean;
  parent:TDirMonitor;
  numBytes: DWORD;

begin
  { Place thread code here }
  quit:=false;
  parent:=TDirMonitor(self.FProRef);
  while (not quit) do
  begin
    GetQueuedCompletionStatus( parent.FCompletionPort, numBytes, state, parent.FPOverlapped, INFINITE);

    if (parent.FPOverlapped<>nil)	then
    //if (state<>0)	then
    begin
      if self.Terminated then
        quit:=true
      else
      begin
        self.Synchronize(self.SendEvent);

        parent.FBytesWrite := 0;
        ZeroMemory(@parent.FNotificationBuffer, SizeOf(parent.FNotificationBuffer));
        ReadDirectoryChanges(parent.FHandle, @parent.FNotificationBuffer,
          SizeOf(parent.FNotificationBuffer), parent.FWatchSubtree, parent.FFilter,
          @parent.FBytesWrite, @parent.FOverlapped, nil);
      end;
    end;

  end;

end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?