What's the best way to do it in .NET?
I always forget what I need to Dispose()
(or wrap with using
).
EDIT: after a long time using WebRequest
, I found out about customizing WebClient
. Much better.
What's the best way to do it in .NET?
I always forget what I need to Dispose()
(or wrap with using
).
EDIT: after a long time using WebRequest
, I found out about customizing WebClient
. Much better.
Run System.Net.WebClient in a seperate thread, set a timer to kill it after your maximum time.
Syncronous Way:
You can also have the asynchronous way:
Here's what I use, it seems to work, but I don't know if it's the best way:
Following Thomas Levesque's comment here, there's a simpler and more generic solution.
We create a
WebClient
subclass with timeout support, and we get all of WebClient's goodness.Sample usage: