TcpListener Pending method returns wrong values
<p>I have the following code in my server side:</p>

<pre><code>// Bind to a specific local port number (SERVER_PORT) and any local IP address.
m_tlServer = new TcpListener(IPAddress.Any, SERVER_PORT);

// Start listening for connection attempts.
m_tlServer.Start();

// Start accepting new clients.
// Sleep until a new client(s) will try to connect to the server.
while (!m_bStopThread)
{
    if (!m_tlServer.Pending())
    {
        // Sleep and try again.
        Thread.Sleep(LISTENING_SLEEP_TIME);
        continue;
    }
    else
    {
        // Accept a new client in a new thread. 
        Thread newthread = new Thread(new ThreadStart(HandleNewConnection)); 
        newthread.Start();
    }
}
</code></pre>

<p>My problem is that when a client tries to connect to the server, the method <code>Pending</code> returns <code>true</code> several times (usually 4 times) and several thread are created.
I tried to replace that while loop by a loop that uses the <code>AcceptTcpClient</code> method (without knowing if there are any connection attempts) and it's works fine. So, I think the problem is caused by <code>Pending</code> method.
Can anyone help me? Thanks, Ofer. </p>
