/// <summary> /// 获取用户长连接轮询验证 /// </summary> /// <param name="userId">用户标识</param> /// <param name="sessionId">长连接轮询验证,0表示失败</param> public void Get(int userId, ref sessionId sessionId) { sessionTimeout value; if (sessions.TryGetValue(userId, out value)) { if (value.Timeout > date.NowSecond) { sessionId = value.SessionId; return; } sessionId.New(); Monitor.Enter(sessionLock); try { sessions[userId] = new sessionTimeout { SessionId = sessionId, Timeout = date.NowSecond.AddTicks(timeoutTicks) }; } finally { Monitor.Exit(sessionLock); } return; } sessionId.Null(); }
/// <summary> /// 清除数据 /// </summary> public void Clear() { Timeout = DateTime.MinValue; SessionId.Null(); }