Guest User

Untitled

a guest
Jul 18th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. //多线程并发时,默认最多只能建立两个持久连接,后续请求也会阻塞,
  2. //增大默认连接数限制可解决此问题
  3.  
  4. //C#默认只允许两个持久连接,http协议的RFC文档也有此建议
  5. System.Net.ServicePointManager.DefaultConnectionLimit = 256;
  6.  
  7. WebRequest wr = WebRequest.Create(URL);
  8. try
  9. {
  10. WebResponse res = wr.GetResponse();
  11. /*
  12. * do something
  13. */
  14. res.Close();
  15. wr.Abort();
  16. }
  17. catch(WebException ex)
  18. {
  19. res.Close();
  20. wr.Abort();
  21. throw ex;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment