C# Stream.ReadTimeout 属性 [英] C# Stream.ReadTimeout Property
问题描述
我正在研究流读取器超时属性.从文档中,我不明白,
I am looking into stream reader timeout property. From the documentation, I did not understand,
- 此属性如何运作?
- 当流读取器超时时会发生什么?
谁能向我解释这些问题或指出一些比这更好的文档.
Can somebody explain me these questions or point out to some better documentation than this.
https://msdn.microsoft.com/en-us/library/system.io.stream.readtimeout(v=vs.110).aspx
示例代码:
TcpClient client = new TcpClient(serverIP, serverTcpPort);
Stream s = client.GetStream();
StreamReader sr = new StreamReader(s);
sr.BaseStream.ReadTimeout = 100;
推荐答案
文档非常清楚地说明,并非每个 Stream 都实现了 ReadTimeout.Stream 的一些子类可以实现这个属性.所以需要查看子类的文档来了解ReadTimeout的用法.您的代码段将与 NetworkStream 一起使用,后者由
The documentation quite clearly says, that not every Stream implements ReadTimeout. Some subclasses of Stream may implement this property. So you need to check the documentation of subclasses to learn about the usage of ReadTimeout. Your code snippet would work with a NetworkStream, which is returned by
Stream s = client.GetStream();
Microsoft 网站确实有一些关于此 NetworkStream 类及其 ReadTimeout
属性的特定文档,您可以在此处找到:https://msdn.microsoft.com/en-us/library/bk6w7hs8(v=vs.110).aspx
The Microsoft website does have some specific documentation for this NetworkStream class and its ReadTimeout
property, which you can find here:
https://msdn.microsoft.com/en-us/library/bk6w7hs8(v=vs.110).aspx
这篇关于C# Stream.ReadTimeout 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!