|
<< Click to Display Table of Contents >> Navigation: Forum > Getting a list of active sessions |
04-15-2018, 11:04 PM:
Hello
Is is possible to get a list of active sessions?
The reason for my question is that i found that there are orphaned files related to expired sessions that was not deleted, and i want to create a periodic clean-up process to delete files not related to active sessions.
PS: My files are stored in application directory with the session ID name.
Mohamed
04-15-2018, 11:56 PM:
(04-15-2018, 11:04 PM)mhammady Wrote: [ -> ]Hello
Is is possible to get a list of active sessions?
The reason for my question is that i found that there are orphaned files related to expired sessions that was not deleted, and i want to create a periodic clean-up process to delete files not related to active sessions.
PS: My files are stored in application directory with the session ID name.
Mohamed
You can try something like the following to get a list of sessions. I found this code, or something similar, online some time back. Some of the locks may be redundant.
Code:
function ListOfSessionHandles:string;
var
i: integer;
LSessions: TList;
LSession:TIWApplication;
begin
result:='';
LSessions:=GSessions.LockList;
try
for i := 0 to (LSessions.Count-1) do
begin
LSession:=LSessions[i];
LSession.Lock;
try
result:=result+'|'+inttostr(TIWUserSession(LSession.Data).SessionWorkstationHandle);
finally
LSession.Unlock;
LSession:=nil;
end;
end;
finally
GSessions.UnLockList(LSessions);
end;
That said, it only gives you a list of active sessions. You'd have to keep up with all sessions in order to find your targets.
Another approach is to "clean up" entirely on some basis. You can drop an entire subdirectory on server shutdown (and add it on startup if necessary).
You might also consider killing the subdirectory if you routinely get down to zero sessions.
Dan
04-16-2018, 03:43 PM:
Thank you Dan. I shall give it a try...
Mohamed
02-27-2020, 10:07 PM:
For future readers:
In IW 15.1+ that's the new way of dealing with session list:
https://github.com/Atozed/IntraWeb/tree/...essionList
https://github.com/Atozed/IntraWeb/tree/...nLookup151
The session list doesn't use any global lock anymore, so it is not possible nor required to "lock" it.
02-28-2020, 04:21 AM:
(02-27-2020, 10:07 PM)Alexandre Machado Wrote: [ -> ]For future readers:
In IW 15.1+ that's the new way of dealing with session list:
https://github.com/Atozed/IntraWeb/tree/...essionList
https://github.com/Atozed/IntraWeb/tree/...nLookup151
The session list doesn't use any global lock anymore, so it is not possible nor required to "lock" it.Yes! And for those who see this and initially react that it might be a problem to migrate, it isn't. Trivial change, see the demos Alex linked.
Dan