Try
Do
read = stream.Read(datain, 0, datain.Length)
responseData = System.Text.Encoding.ASCII.GetString(datain, 0, read)
finalResponse = finalResponse + responseData
Loop While read > 0
Catch ex As Exception
有时候程序会停留在那个stream.read如果失败了我想移动。
如何解决这个问题?
答案 0 :(得分:0)
答案 1 :(得分:0)
你必须使用stream.ReadTimeout(以毫秒为单位的时间)
你必须再次使用try catch TimeOutException
Try
stream.ReadTimeout(5000);
Do
try
{
read = stream.Read(datain, 0, datain.Length)
responseData = System.Text.Encoding.ASCII.GetString(datain, 0, read)
finalResponse = finalResponse + responseData
}
catch err as TimeoutException
{
read = 1; //To avoid quiting the loop
}
Loop While read > 0
Catch ex As Exception
也许我的语法并不完美,因为我在c#中编码,但两种语言的解析仍然相同。