07-15-2019, 09:51 AM
(This post was last modified: 07-15-2019, 10:02 AM by Alexandre Machado.)
(07-15-2019, 09:00 AM)matija Wrote: My function in ServerController:
Try this code instead. Session list doesn't use any locking mechanism. Have in mind that GSessions.Terminate() might fail to terminate the desired session if it is currently locked by the user. It is not possible to remove a session being used by another thread.
Code:
procedure TIWServerController.KillDoubleSession(const Username: string);
var
LSessions: TStringList;
i:Integer;
cAppID: string;
LFound: Boolean;
begin
cAppID:='';
LSessions := TStringList.Create;
try
gSessions.GetList(LSessions);
LFound := False;
for i := 0 to Pred(LSessions.Count) do
begin
gSessions.Execute(LSessions[i],
procedure(aSession: TObject)
var
LSession: TIWApplication absolute aSession;
begin
LFound := (LSession.Data as TIWUserSession).WebUser.Username = Username;
if LFound then
cAppID := LSessions[i];
end
);
if LFound then
Break;
end;
finally
LSessions.Free;
end;
if cAppID <>'' then
begin
GSessions.Terminate(cAppID);
end;
end;