I suggest you using socket.Poll(1000,SelectMode.Read); for more details see http://msdn.microsof...y/cc532890.aspx
So instead of socket.Accept() do this:
class MyTcpListener;
{
public bool StopListening=false;
private Socket socket;
public Socket Accept()
{
while(!socket.Poll(1000,SelectMode.Read))
{
if(StopListening)
return null;
}
return socket.Accept();
}
}
Ofcource this is pretty stupid example you can do much better...