public async void Start() { if (Lib.Helper.NetworkHelper.IsPortInUse(Port)) { return; } _listener = new TcpListener(new IPEndPoint(IPAddress.Any, Port)); _listener.Start(); _cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = _cancellationTokenSource.Token; while (!cancellationToken.IsCancellationRequested) { try { var cid = _nextConnectionId++; _logger.LogInformation($"<ac {cid} {Thread.CurrentThread.ManagedThreadId}"); var tcpClient = await _listener.AcceptTcpClientAsync(); _logger.LogInformation($">ac {cid} {Thread.CurrentThread.ManagedThreadId} {tcpClient.Client.RemoteEndPoint}"); var session = new ImapSession(this, tcpClient); _ = session.Start(); } catch { } } }
public async void Start() { if (Lib.Helper.NetworkHelper.IsPortInUse(Port)) { return; } _listener = new TcpListener(new IPEndPoint(IPAddress.Any, Port)); _listener.Start(); _cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = _cancellationTokenSource.Token; while (!cancellationToken.IsCancellationRequested) { try { var tcpClient = await _listener.AcceptTcpClientAsync(); var session = new ImapSession(this, tcpClient); session.Start(); } catch { } } }