E
Ezequiel
Hi,
I´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
([email protected])
I´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
([email protected])