05-11-2021, 03:06 PM
(05-11-2021, 10:45 AM)Alexandre Machado Wrote: This code works correctly, as expected.
It terminates locks and terminates the session.
I believe that your problem is that you are trying to lock (and terminate) the same session that is running the command and that, by design, is not allowed. You can terminate all other sessions, except your own session, using this code.
To terminate your own session you must explicitly call IWApplication.Terminate, as usual.
Another point is that you don't need (nor should) release the application forms. The Session itself takes care of all forms when it is being released.
Code:
Code:procedure TIWForm1.TerminateSession(const AAppId: string);
var
lApp: TIWApplication;
lExpired, lLocked: Boolean;
begin
lApp := gSessions.LookupAndLock(AAppId, lExpired, lLocked);
if Assigned(lApp) and not lExpired then
begin
try
lApp.Terminate;
finally
lApp.Unlock;
end;
end;
end;
Hi!
I will try it and let you know the results. Thanks!