I want to download a single file with Multi-Threads in C#. e.g: Thread1 start downloading from 1% to 40%. Thread2 start downloading from 41% to 70%. Thread3 start downloading from 71% to 100%
Please suggest me some code. Thanks in advance
How about using HttpRequest class, with AddRange method called. This should a header with offset from which to start downloading.
var request = HttpWebRequest.Create(new Uri("http://www.myurl.com/hugefile"));
request.Method = "GET";
request.AddRange(offset_for_this_thread); // I assume you have calculated this
// before firing threads
Stream reponseStream = request.GetResponse().GetResponseStream();
You can then read from ´responseStream´ the data and merge it with the other threads once it is done.
However, as noticed by everybody else, this will only bring value if you have two adapters, both connected to internet, and you have some kind of bandwidth balancing between those adapter... Otherwise Windows wil likely divert everything to the same connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With