惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - oo复oo

Asp.net Ajax 中的脚本错误: 'Sys'未定义 的解决方法 学习xml 之"实体"篇 - oo复oo - 博客园 该死的dudu加速器广告终于被清除了 第一次安装DNN 网站 网站总算安装成功了 开始行动了 .net 2.0 访问Oracle --与Sql Server的差异,注意事项,常见异常 Ado.net 与NHibernate的关系? 一个基于.net Framework 2.0 的图形处理工具 贴一篇关于asp.net性能计数器的文章,供以后参考 你的.net 2.0 真的能与1.1 安全正确地运行在同一台电脑上吗? 小心Server Application Unavailable 错误 贴一篇关于asp.net性能计数器的文章,供以后参考 使用@Page指令的Src 属性 简化对老版本的 asp.net程序的维护 新年到,祝大家新年快乐 学习xml 之"刘姥姥进大观园" -----xml概述 学习xml 之" 给个理由先" 此gmail非彼gmail 在.net 中调用win32API :GetBitmapBits ,获取位图的颜色数组,发送给打印机。 通过串口编程控制打印机
WebRequest 使用不当可能会造成线程阻塞
oo复oo · 2005-11-08 · via 博客园 - oo复oo

        使用WebRequest向网站提交数据并请求资源时需要注意,如果使用不当,可能造成阻塞,而且错误原因很难查找。
  
         很多时候我们使用WebRequest 类只是为了向网站提交数据,并不想从网站获取数据,所以可能会这样:

WebRequest wr=WebRequest.Create(URL);
            
try
            {
                WebResponse res
=wr.GetResponse();
            }
            
catch(WebException ex)
            {
                
throw ex;
            }

    只调用GetResponse()方法向服务器提交数据后就不管了。 此时可能会出问题。

     今天在写一个向Web提交数据的程序时,由于只需提交,无需获取数据,我便简单地使用上述代码搞定。测试时没有问题。 在后业的使用中,当不断循环向Web提交数据,。问题出来了,程序停止了。 打开vs.net 进入调试模式,单步调试时,它又不出错了。 经过n次重复才发现问题症结所在:当快速反复提交n次数据后,线程才会阻塞。 缓慢的单步执行时,问题很难暴露。修改为如下代码后问题解决:

1 WebRequest wr=WebRequest.Create(GetFullURL(Params));
2             try
3             {
4                 wr.GetResponse().Close();
5             }
6             catch(WebException ex)
7             {
8                 throw ex;
9             }

使用WebRequest 时,一定要将GetResponse()方法返回的WebResponse关闭,就算你压跟不需要使用它,也得这样做。否则你的程序可能突然停止或界面没响应(阻塞)