title: How do I download a file in vb .net with a download timeout?
body: <p>I want to download thousands of files from the web and save them locally.  What is the most efficient way?  It is important the failures timeout within 10 seconds.</p>
  
  <p>Is there a better way to stream one stream into another?  Maybe a smaller buffer, like 1024 bytes at a time, is more efficient for large files?</p>
  
  <pre><code>Dim w_req As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create("http://blah.blah.blah/blah.html"), System.Net.HttpWebRequest)
  w_req.Timeout = 10000
  Dim w_res As System.Net.HttpWebResponse = CType(w_req.GetResponse(), System.Net.HttpWebResponse)
  Dim br As New System.IO.BinaryReader(w_res.GetResponseStream())
  Dim fs As New System.IO.FileStream(LocalFileName, IO.FileMode.CreateNew, IO.FileAccess.Write, IO.FileShare.Write)
  Dim b() As Byte = br.ReadBytes(CInt(br.BaseStream.Length))
  fs.Write(b, 0, b.Length)
  fs.Close()
  br.Close()
  </code></pre>