// TODO - if clients simply abandon their session, the session dictoinary could grow uncontrollably. should be loop through (separate thread is ok) // the collection on every access to check for expired connections? maybe have some background process? public MySession getSession(string token) { if (String.IsNullOrEmpty(token)) { return(new MySession() { LastUsed = DateTime.Now }); } if (!_sessions.ContainsKey(token)) { return(new MySession()); } MySession clientSession = _sessions[token]; // check timeout if (clientSession.hasExpired()) { _sessions.Remove(token); // remove session if timed out return(new MySession()); // give client a new bare MySession } clientSession.LastUsed = DateTime.Now; return(clientSession); }