好吧,我担心我在这一点上有点失落。以下代码给出了CA 2000警告,“'新WebRequestHandler()'未沿所有异常路径放置”。
this.webHandler = new WebRequestHandler()
{
AllowAutoRedirect = true,
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache),
CookieContainer = cookies,
ReadWriteTimeout = 5000
};
我挣扎了20分钟,然后发现我确信在功能上相同的代码没有给出同样的警告。
this.webHandler = new WebRequestHandler();
this.webHandler.AllowAutoRedirect = true;
this.webHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
this.webHandler.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
this.webHandler.CookieContainer = cookies;
this.webHandler.ReadWriteTimeout = 5000;
显然,解决方案是使用后一种方法(或者只是抑制警告),但是我不知道的第一种方法是否有问题?