public void StartDispatching(TcpListener tcpListener, ILogger logger, IProtocolFactory protocolFactory, IAppDocument appDocument) { IServerProtocol serverProtocol; tcpListener.Start(); // Run forever, accepting and spawning threads to service each connection. for (; ;) { try { // Block waiting for a connection. Socket clientSocket = tcpListener.AcceptSocket(); serverProtocol = protocolFactory.CreateServerProtocol(clientSocket, logger); // A client has connected so create a thread to handle it. ParameterizedThreadStart clientThreadStart = new ParameterizedThreadStart(serverProtocol.HandleClientConnection); Thread clientThread = new Thread(clientThreadStart) { IsBackground = true }; clientThread.Start(); logger.WriteEntry("Created and started Thread = " + clientThread.GetHashCode()); } catch (System.IO.IOException ioException) { logger.WriteEntry("Exception = " + ioException.Message); } } // Unreachable. }