Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
MSDN 上的文档包含这句话,这是相当模棱两可的:
如果远程主机关闭或关闭连接,Available 可能会抛出 SocketException。
这意味着什么?文档不清楚。
什么决定了 Available 属性是否会抛出?
这意味着什么?
您需要将其包装在一个try..catch块中,因为它可能会引发异常。
try..catch
此外,我认为何时将是一个实施细节。反编译 System.Net 程序集以亲自查看它何时抛出。
我怀疑如果远程方正确关闭套接字(并且在这种情况下0将返回),它不会抛出,但这不是你可以依赖的。
0