|
tech
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
HELP with Webclient and simultaneous threadsI´m coding an application that is able to download various mp3 files at the same time. For each mp3 download i´m using a thread. Each thread uses System.net.WebClient. If i try to download 3 files at the same time, 2 of them starts downloading (i see in the explorer the size incresing with the time) however the third mp3 never starts downloading and after some seconds, application throws a timeout exception in the client.OpenRead(URL); line. Below is the code of the thread: try { // Get HTML data WebClient client = new WebClient(); Stream data = client.OpenRead(URL); // HERE HAPPENS THE EXCEPTION BinaryReader reader = new BinaryReader(data); byte[] str = new byte[1024]; int intByteLeidos; BinaryWriter BWEscritorBin = new BinaryWriter(new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.None)); try { intByteLeidos = reader.Read(str, 0, 1024); while (intByteLeidos>0) { /* if (prgBar.Maximum > 100) { prgBar.Value += intByteLeidos; }*/ BWEscritorBin.Write(str,0,intByteLeidos); intByteLeidos = reader.Read(str, 0, 1024); } data.Close(); return 1; } catch (IOException expIO) { System.Windows.Forms.MessageBox.Show(expIO.Message,"Exception"); data.Close(); return 0; } } catch (WebException exp) { System.Windows.Forms.MessageBox.Show(exp.Message, "Exception"); return 0; } } } Any help will be really appreciated. Ezequiel Naftali (enaft***@pisol.com.ar) Ezequiel <ezequiel.naft***@gmail.com> wrote:
> I´m coding an application that is able to download various mp3 files If they're all going to the same host, you'll be limited by the number > at the same time. > For each mp3 download i´m using a thread. Each thread uses > System.net.WebClient. > If i try to download 3 files at the same time, 2 of them starts > downloading (i see in the explorer the size incresing with the time) > however the third mp3 never starts downloading and after some seconds, > application throws a timeout exception in the client.OpenRead(URL); > line. of connections. Try setting ServicePointManager.DefaultConnectionLimit - I don't know if that's actually the appropriate place, but it could well be. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Jon,
They use the same connection limit as Internet Explorer, by nature. Why don't you try a basic HTTPRequest? Rgs, "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message Ezequiel <ezequiel.naft***@gmail.com> wrote:news:MPG.1ff27b8d454fd00b98d713@msnews.microsoft.com... > I´m coding an application that is able to download various mp3 files If they're all going to the same host, you'll be limited by the number> at the same time. > For each mp3 download i´m using a thread. Each thread uses > System.net.WebClient. > If i try to download 3 files at the same time, 2 of them starts > downloading (i see in the explorer the size incresing with the time) > however the third mp3 never starts downloading and after some seconds, > application throws a timeout exception in the client.OpenRead(URL); > line. of connections. Try setting ServicePointManager.DefaultConnectionLimit - I don't know if that's actually the appropriate place, but it could well be. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too |
|||||||||||||||||||||||