private async Task DoStartSessionAsync(CommandMessage msg) { string sid = msg.Args[1]; if (this.sessionMap.TryRemove(sid, out var session)) { session.Close(); } session = new TcpMapClientSession(this.Client, sid); this.sessionMap.TryAdd(sid, session); try { await session.StartAsync(); msg.Args[1] = "OK"; } catch (Exception x) { this.OnError(x); msg.Args[1] = "Error"; } msg.Name = "StartSessionResult"; this.LogMessage("TcpMapClientWorker sending " + msg); await this.swrite.WriteAsync(msg.Pack()); }
private async Task ProvidePreSessionAsync() { while (this.IsConnected) { try { var session = new TcpMapClientSession(this.Client, null); lock (this.presessions) { this.presessions.Add(session); } try { await session.WaitUpgradeAsync(); } finally { lock (this.presessions) { this.presessions.Remove(session); } } if (session.SessionId != null) { this.sessionMap.TryAdd(session.SessionId, session); this.LogMessage("Warning:ClientWorker Session Upgraded " + session.SessionId); } else { this.LogMessage("Warning:ClientWorker Session Closed ? " + this.IsConnected + " , " + session.SessionId); } } catch (Exception x) { this.OnError(x); } await Task.Yield(); //await Task.Delay(2000); } }