1 {
2  *****************************************************************************
3   See the file COPYING.modifiedLGPL.txt, included in this distribution,
4   for details about the license.
5  *****************************************************************************
6 
7   Author: Pascal Riekenberg
8 
9   Abstract:
10     Provides a general classes for calling an event when a process ends
11 }
12 unit NotifyProcessEnd;
13 
14 {$mode objfpc}{$H+}
15 
16 interface
17 
18 uses
19   Classes, SysUtils, process;
20 
21 type
22   { TNotifyProcessEnd }
23 
24   TNotifyProcessEnd = class(TThread)
25   private
26     fEvent: TThreadMethod;
27     fProcess: TProcess;
28   protected
29     procedure Execute; override;
30   public
31     constructor Create(pProcess: TProcess; pEvent: TThreadMethod);
32   end;
33 
34 implementation
35 
36 { TNotifyProcessEnd }
37 
38 procedure TNotifyProcessEnd.Execute;
39 begin
40   fProcess.Execute;
41   Synchronize(fEvent);
42   fProcess.Free;
43 end;
44 
45 constructor TNotifyProcessEnd.Create(pProcess: TProcess; pEvent: TThreadMethod);
46 begin
47   inherited Create(True);
48   fProcess := pProcess;
49   fProcess.Options := fProcess.Options + [poWaitOnExit];
50   fEvent := pEvent;
51   FreeOnTerminate := True;
52   Start;
53 end;
54 
55 end.
56 
57