C# 为什么HttpWebRequest有时会抛出OperationCanceledException或WebException.timeout?

C# 为什么HttpWebRequest有时会抛出OperationCanceledException或WebException.timeout?,c#,httpwebrequest,C#,Httpwebrequest,最近,我在使用HttWebRequest验证项目中的timeout和ReadWriteTimeout函数时遇到了一个严重问题 有两段代码,第一段抛出 未处理的异常:System.Net.WebException:操作已超时。 在System.Net.HttpWebRequest.GetResponse()中 HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(“https://www.stackoverflow.com"); 请求超时=5000;

最近,我在使用
HttWebRequest
验证项目中的
timeout
ReadWriteTimeout
函数时遇到了一个严重问题

有两段代码,第一段抛出

未处理的异常:System.Net.WebException:操作已超时。 在System.Net.HttpWebRequest.GetResponse()中

HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(“https://www.stackoverflow.com");
请求超时=5000;
HttpWebResponse=(HttpWebResponse)request.GetResponse();
HttpWebRequest2=(HttpWebRequest)WebRequest.Create(“https://www.stackoverflow.com");
请求2.超时=1;
HttpWebResponse response2=(HttpWebResponse)request2.GetResponse();
下一节是代码抛出

未处理的异常:System.OperationCanceledException:操作已取消。 在System.Net.HttpWebRequest.GetResponse()中

HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(“https://www.stackoverflow.com");
请求超时=5000;
HttpWebResponse=(HttpWebResponse)request.GetResponse();
请求=(HttpWebRequest)WebRequest.Create(“https://www.stackoverflow.com");
请求超时=1;
response=(HttpWebResponse)request.GetResponse();
我不明白为什么它会抛出不同的异常


我想一个可能的原因是,
保持活动状态
默认为真?但是我头晕目眩。

你有没有找到解决办法?调用
GetResponse
时,我也遇到了
OperationCanceledException
GetResponse
的文档中没有记录此异常。