-
Notifications
You must be signed in to change notification settings - Fork 5
/
BackgroundThreadUnit.pas
62 lines (52 loc) · 1.13 KB
/
BackgroundThreadUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
unit BackgroundThreadUnit;
interface
uses
System.Classes;
type
TBackgroundThread = class(TThread)
private
FPaused: Boolean;
// increase capabilities here
// FTerminated: Boolean;
// FOnTerminate: TNotifyEvent;
protected
procedure Execute; override;
public
procedure Pause;
procedure Continue;
// procedure Terminate;
// property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate;
end;
implementation
uses
System.SysUtils, System.IOUtils;
procedure TBackgroundThread.Continue;
begin
FPaused := False;
end;
// process something here
procedure TBackgroundThread.Execute;
var
LogFile: TextFile;
begin
try
FPaused := False;
AssignFile(LogFile, 'C:\Temp\Logs.log');
Rewrite(LogFile);
while not Terminated do
begin
if not FPaused then
begin
WriteLn(LogFile, 'Logs From Background Thread: ' + DateTimeToStr(Now));
end;
TThread.Sleep(1000);
end;
finally
CloseFile(LogFile);
end;
end;
procedure TBackgroundThread.Pause;
begin
FPaused := True;
end;
end.