private void OnExit() { IsExitingValue.Update(b => { if (!IsRunningValue.Check(bb => bb)) { return(b); } if (!b) { Server.NotifySessionQuit(this); } return(true); }); }
//线程安全 private void OnExit() { bool Done = false; IsExitingValue.Update(b => { if (!IsRunningValue.Check(bb => bb)) { Done = true; return(b); } Done = b; return(true); }); if (Done) { return; } Server.NotifySessionQuit(this); }
public void Dispose() { if (IsDisposed) { return; } IsDisposed = true; IsExitingValue.Update(b => true); ssm.NotifyExit(); Server.SessionMappings.DoAction(Mappings => { if (Mappings.ContainsKey(Context)) { Mappings.Remove(Context); } }); Server.ServerContext.TryUnregisterSession(Context); si.Dispose(); IsRunningValue.Update(b => false); SpinWait.SpinUntil(() => ssm.IsExited()); Context.Dispose(); IsExitingValue.Update(b => false); if (Server.ServerContext.EnableLogSystem) { Server.ServerContext.RaiseSessionLog(new SessionLogEntry { Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "Sys", Name = "SessionExit", Message = "" }); } }