Merge pull request #246 from mgrinzPlayer/autoattach-Thread-instead-of-Timer
autoattach Thread instead of Timer
This commit is contained in:
commit
3fdee513c4
@ -2213,6 +2213,7 @@ object MainForm: TMainForm
|
||||
top = 488
|
||||
end
|
||||
object AutoAttachTimer: TTimer
|
||||
Enabled = false
|
||||
Interval = 2000
|
||||
OnTimer = AutoAttachTimerTimer
|
||||
left = 416
|
||||
|
@ -208,6 +208,18 @@ type
|
||||
procedure Execute; override;
|
||||
end;
|
||||
|
||||
type
|
||||
TAutoAttachThread=class(TThread)
|
||||
private
|
||||
fInterval: integer;
|
||||
public
|
||||
CurrentProcessList: TStringList;
|
||||
procedure autoattachcheck;
|
||||
constructor Create(CreateSuspended: boolean);
|
||||
procedure Execute; override;
|
||||
published
|
||||
property Interval: integer read fInterval write fInterval;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
@ -872,7 +884,7 @@ type
|
||||
procedure updated3dgui;
|
||||
procedure RefreshCustomTypes;
|
||||
|
||||
procedure autoattachcheck;
|
||||
procedure autoattachcheck(pl: TStringList = nil); // can be called by AutoAttachTimer or AutoAttachThread
|
||||
function openprocessPrologue: boolean;
|
||||
procedure openProcessEpilogue(oldprocessname: string; oldprocess: dword;
|
||||
oldprocesshandle: dword; autoattachopen: boolean = False);
|
||||
@ -935,6 +947,7 @@ type
|
||||
var
|
||||
MainForm: TMainForm;
|
||||
ToggleWindows: TTogglewindows;
|
||||
AutoAttachThread: TAutoAttachThread;
|
||||
|
||||
implementation
|
||||
|
||||
@ -7267,7 +7280,9 @@ begin
|
||||
Caption := cenorm + ' ' + rsEXPIRED + '!';
|
||||
|
||||
if autoattachtimer.Enabled then
|
||||
autoattachcheck;
|
||||
autoattachcheck
|
||||
else
|
||||
AutoAttachThread:=TAutoAttachThread.Create(false);
|
||||
|
||||
|
||||
|
||||
@ -8782,12 +8797,40 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.autoattachcheck;
|
||||
procedure TAutoAttachThread.autoattachcheck;
|
||||
begin
|
||||
MainForm.autoattachcheck(CurrentProcessList);
|
||||
end;
|
||||
|
||||
constructor TAutoAttachThread.Create(CreateSuspended: boolean);
|
||||
begin
|
||||
Interval:=2000;
|
||||
CurrentProcessList:=TStringList.Create;
|
||||
inherited Create(CreateSuspended);
|
||||
end;
|
||||
|
||||
procedure TAutoAttachThread.Execute;
|
||||
begin
|
||||
while not terminated do
|
||||
begin
|
||||
if ((MainForm.autoattachlist = nil) or (formsettings = nil) or (MainForm.extraautoattachlist = nil)) or
|
||||
((MainForm.autoattachlist.Count+MainForm.extraautoattachlist.Count)<1) or
|
||||
((not formsettings.cbAlwaysAutoAttach.Checked) and ((processhandle <> 0) or (processid <> 0))) then
|
||||
begin
|
||||
sleep(Interval);
|
||||
continue;
|
||||
end;
|
||||
|
||||
getprocesslist(CurrentProcessList,false,true);
|
||||
synchronize(autoattachcheck);
|
||||
sleep(Interval);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.autoattachcheck(pl: TStringList = nil);
|
||||
var
|
||||
pl: TStringList;
|
||||
i, j, k: integer;
|
||||
newPID: dword;
|
||||
pli: PProcessListInfo;
|
||||
a: string;
|
||||
p: string;
|
||||
|
||||
@ -8795,13 +8838,6 @@ var
|
||||
oldphandle: thandle;
|
||||
attachlist: TStringList;
|
||||
begin
|
||||
if (autoattachlist = nil) or (formsettings = nil) or (extraautoattachlist = nil) then
|
||||
exit;
|
||||
|
||||
if (not formsettings.cbAlwaysAutoAttach.Checked) and
|
||||
((processhandle <> 0) or (processid <> 0)) then
|
||||
exit;
|
||||
|
||||
attachlist := TStringList.Create;
|
||||
try
|
||||
attachlist.AddStrings(autoattachlist);
|
||||
@ -8813,8 +8849,11 @@ begin
|
||||
//in case there is no processwatcher this timer will be used to enumare the processlist every 2 seconds
|
||||
|
||||
|
||||
pl := TStringList.Create;
|
||||
getprocesslist(pl);
|
||||
if pl=nil then
|
||||
begin
|
||||
pl := TStringList.Create;
|
||||
getprocesslist(pl,false,true);
|
||||
end;
|
||||
|
||||
try
|
||||
for i := 0 to attachlist.Count - 1 do
|
||||
@ -8859,17 +8898,7 @@ begin
|
||||
// pl.IndexOf(autoattachlist.items[i]);
|
||||
|
||||
finally
|
||||
for i := 0 to pl.Count - 1 do
|
||||
if pl.Objects[i] <> nil then
|
||||
begin
|
||||
pli := pointer(pl.Objects[i]);
|
||||
if pli.processIcon > 0 then
|
||||
DestroyIcon(pli.processIcon);
|
||||
freemem(pli);
|
||||
pli:=nil;
|
||||
end;
|
||||
|
||||
pl.Free;
|
||||
cleanProcessList(pl);
|
||||
end;
|
||||
|
||||
end;
|
||||
@ -8882,6 +8911,13 @@ end;
|
||||
|
||||
procedure TMainForm.AutoAttachTimerTimer(Sender: TObject);
|
||||
begin
|
||||
if (autoattachlist = nil) or (formsettings = nil) or (extraautoattachlist = nil) then
|
||||
exit;
|
||||
|
||||
if (not formsettings.cbAlwaysAutoAttach.Checked) and
|
||||
((processhandle <> 0) or (processid <> 0)) then
|
||||
exit;
|
||||
|
||||
autoattachcheck;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user