09-09-2020, 09:40 AM
Hi!
In order to let some forms be terminated I get the session list with; gSessions.GetList(alst); as one of the last things in the event IWServerControllerBaseNewSession() in the server control unit
But it will almost always not work the second time around, the first time is OK.
I've tried to push it to a later time, when the form is up and running (with a timer 5000), but it is the same behaviour.
Thx Martin
In order to let some forms be terminated I get the session list with; gSessions.GetList(alst); as one of the last things in the event IWServerControllerBaseNewSession() in the server control unit
But it will almost always not work the second time around, the first time is OK.
I've tried to push it to a later time, when the form is up and running (with a timer 5000), but it is the same behaviour.
Thx Martin
Code:
procedure TIWServerController.CleanUpForms(ASession: TIWApplication);
var
alst: TStringList;
aid: string;
app: TIWApplication;
exp, al: boolean;
ok: boolean;
cnt: integer;
begin
if _LogEnabled then
_Log('Trying to clean-up session list');
try
ok:=false;
cnt:=0;
repeat
alst:=TStringList.Create;
try
gSessions.GetList(alst);
ok:=true;
except
Inc(cnt);
if cnt = 100 then begin
if _LogEnabled then
_Log('**Warning: Could not retrieve session list from IntraWeb platform');
Exit;
end;
Sleep(50);
end;
until ok;
if _LogEnabled then begin
if cnt > 0 then
_Log('Retry count is: ' + IntToStr(cnt));
_Log('Number of sessions currently in the list: ' + IntToStr(alst.Count));
end;
for aid in alst do begin
if aid <> ASession.AppID then begin
app:=gSessions.LookupAndLock(aid, exp, al);
if Assigned(app) and not exp then begin
if app.Name = ASession.Name then begin
if _LogEnabled then
_Log('Session "' + app.AppID + '" will be terminated');
app.Unlock;
app.Terminate;
app.Free;
end else begin
app.Unlock;
end;
end;
end;
end;
finally
alst.Free;
end;
if _LogEnabled then
_Log('Number of sessions (from gSessions): ' + IntToStr(gSessions.Count));
end;