09-09-2020, 10:24 PM
(This post was last modified: 09-09-2020, 10:26 PM by Alexandre Machado.)
I don't understand what you are trying to accomplish exactly... You said that you are trying to terminate some forms but you are actually terminating some sessions, correct?
How's this method called/triggered? From an user event?
You are terminating one specific session from another session (i.e. from Session A you terminate Session B)?
If so, the code looks good to me, most of it. But the problem relies on the terminate itself. *Don't free the session yourself*.
After being terminated, session will be collected by the clean up thread which runs in the background, and freed. If you free it yourself, the clean up thread won't be able to do the proper clean up.
How's this method called/triggered? From an user event?
You are terminating one specific session from another session (i.e. from Session A you terminate Session B)?
If so, the code looks good to me, most of it. But the problem relies on the terminate itself. *Don't free the session yourself*.
Code:
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.Terminate; // terminate first
end;
app.Unlock; // then unlock it. Don't free it!
end;
end;
After being terminated, session will be collected by the clean up thread which runs in the background, and freed. If you free it yourself, the clean up thread won't be able to do the proper clean up.