Ensure streamreader doesn't hang waiting for data
问题 The code below reads everything there is to read from tcp client stream, and on the next iteration it will just sit there on the Read() (i'm assuming waiting for data). How can I ensure it doesn't and just returns when there's nothing there to read? Do I have to set low timeout, and respond to an exception when it fails out? Or there's a better way? TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect(ip, port); Stream stm = tcpclnt.GetStream(); stm.Write(cmdBuffer, 0, cmdBuffer.Length); byte