简体   繁体   中英

WebClient TimeOut

I've written a program that opens a site to read with WebClient.OpenRead every 30 seconds. but after 1 or 2 times, it can't continue doing that and throws an exception of timeout. What's wrong here?

Hmm... My intuition says:

Do you dispose of the stream correctly too? If you don't, the stream will likely remain open, causing the server's resource limits (2 connections per client, for instance), to hit you.

Using an using construct will dispose of the stream automatically for you.

using(var stream = WebClient.OpenRead(...)) {
   // Use the stream.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM