public void AcceptClients() { while (true) { var client = MasterServer.AcceptTcpClient(); if (client.Connected) { Task.Factory.StartNew(() => { var ch = new ConnectionHandler(client, this); ch.HandleConnection(); }); ConnectClients.Add(client); Console.WriteLine("Client added and is now awaiting work: " + client.GetHashCode()); } } }
private void AcceptClients() { while (!IsDone()) { try { var client = MasterServer.AcceptTcpClient(); if (client.Connected) { var ch = new ConnectionHandler(client, this); Task.Factory.StartNew(() => { ch.HandleConnection(); }); ConnectClients.Add(ch); Console.WriteLine("Client added and is now awaiting work: " + client.GetHashCode()); } } catch (Exception) { Console.WriteLine("Reached the end of dictionary"); } } }