You are burning cpu cycles busy polling for a connection. Considering most of the time Pending
is returning false, your loop is spinning around like this:
while (!ssStop)
{
tcpReceiver = new TcpClient();
myEventHandle.WaitOne(10, false);
}
Now if myEventHandle is unset then the 10ms delay in WaitOne
would effectively throttle execution but my guess would be that the event is set so that WaitOne
immediately returns true
.
It is not necessary to poll for a connection since AcceptTcpClient
will block waiting for a connection. So if you changed your code around a bit it should work as expected:
while (!ssStop)
{
TcpClient tcpReceiver = ssTcpListener.AcceptTcpClient(); // this blocks
...
}