Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a list of active sessions
#1
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
Reply
#2
(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
Reply
#3
Thank you Dan. I shall give it a try...

Mohamed
Reply
#4
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.
Reply
#5
(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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)