스레드 서버로 만든 채팅 서버가 있는데 제대로 작동하고 5 명의 클라이언트가 연결되어 있지만 CPU 사용이 100 % 증가합니다! 프로브는 Thread.sleep를 (30000)을 넣어,하지만 문제가 해결되지 않는, 여기스레드 서버 Cpu 사용률 100 % C#
public void StartListening()
{
// Get the IP of the first network device, however this can prove unreliable on certain configurations
IPAddress ipaLocal = ipAddress;
// Create the TCP listener object using the IP of the server and the specified port
tlsClient = new TcpListener(ipaLocal, 1986);
// Start the TCP listener and listen for connections
tlsClient.Start();
// The while loop will check for true in this before checking for connections
ServRunning = true;
// Start the new tread that hosts the listener
thrListener = new Thread(KeepListening);
thrListener.Start();
}
private void KeepListening()
{
// While the server is running
while (ServRunning == true)
{
// Accept a pending connection
tcpClient = tlsClient.AcceptTcpClient();
// Create a new instance of Connection
Connection newConnection = new Connection(tcpClient);
Thread.Sleep(30000);
}
}
}