Opc.Ua.Server.SessionManager.CloseSession C# (CSharp) Method

CloseSession() public method

Closes the specifed session.
This method should not throw an exception if the session no longer exists.
public CloseSession ( NodeId sessionId ) : void
sessionId NodeId
return void
        public virtual void CloseSession(NodeId sessionId)
        {
            // find the session.
            Session session = null;

            lock (m_lock)
            {
                foreach (KeyValuePair<NodeId,Session> current in m_sessions)
                {
                    if (current.Value.Id == sessionId)
                    {
                        session = current.Value;
                        m_sessions.Remove(current.Key);
                        break;
                    }
                }
            }

            if (session != null)
            {            
                // raise session related event.
                RaiseSessionEvent(session, SessionEventReason.Closing);
                
                // close the session.
                session.Close();

                // update diagnostics.
                lock (m_server.DiagnosticsLock)
                {
                    m_server.ServerDiagnostics.CurrentSessionCount--;
                }
            }

        }