473,941 Members | 30,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP with Webclient and simultaneous threads

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.WebC lient.
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(da ta);
byte[] str = new byte[1024];
int intByteLeidos;

BinaryWriter BWEscritorBin = new BinaryWriter(ne w
FileStream(Path , FileMode.Create , FileAccess.Writ e, FileShare.None) );
try {
intByteLeidos = reader.Read(str , 0, 1024);
while (intByteLeidos> 0) {
/* if (prgBar.Maximum 100)
{
prgBar.Value += intByteLeidos;
}*/
BWEscritorBin.W rite(str,0,intB yteLeidos);
intByteLeidos = reader.Read(str , 0, 1024);

}
data.Close();
return 1;
} catch (IOException expIO) {

System.Windows. Forms.MessageBo x.Show(expIO.Me ssage,"Exceptio n");
data.Close();
return 0;
}
} catch (WebException exp) {
System.Windows. Forms.MessageBo x.Show(exp.Mess age,
"Exception" );
return 0;
}
}

}
Any help will be really appreciated.

Ezequiel Naftali
(en******@pisol .com.ar)

Dec 19 '06 #1
2 2593
Ezequiel <ez************ **@gmail.comwro te:
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.WebC lient.
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.
If they're all going to the same host, you'll be limited by the number
of connections. Try setting ServicePointMan ager.DefaultCon nectionLimit
- I don't know if that's actually the appropriate place, but it could
well be.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 19 '06 #2
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.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
Ezequiel <ez************ **@gmail.comwro te:
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.WebC lient.
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.
If they're all going to the same host, you'll be limited by the number
of connections. Try setting ServicePointMan ager.DefaultCon nectionLimit
- I don't know if that's actually the appropriate place, but it could
well be.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1423
by: Christopher Ireland | last post by:
Hi -- I'm not looking for a definitive solution here, just some pointers in the right direction. I have a very simple UserControl in an HTML page enclosed within <object> tags virtually identical to this one: http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=187 The only difference is that I have added a public method:
2
5383
by: xzzy | last post by:
I have .net 1.1 c# . . . . . using System.Net only lists sockets what do I need to do to be able to do: using System.Net.WebClient;
2
1293
by: trialproduct2004 | last post by:
Hi all, i am having c# application. I have bunch of URL's which i want to validate. that means i want to check whether those url's are valid or not. When i start processing url's one by on synchronysly its taking lots of time. So what i want is to split above task. I want to use threading in this case to make process faster. I want to created threads which are processing say 5 urls at a time. Like that i want to create some threads...
1
2079
by: Lisa | last post by:
Hi, I'm trying to show some sign of activity while my app downloads a file from the internet. My download routine is such: Private Sub DownloadWebFile() Dim wdc As New System.Net.WebClient() Try wdc.DownloadFile(FTD, "temp.temp") 'FTD is a global string, the address & filename to download
2
5987
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like this: System.Net.WebClient client=new System.Net.WebClient();
1
6507
by: Mad Scientist Jr | last post by:
For some reason I can't get a WebClient to access an outside URL from behind our firewall. The code works when it runs outside the firewall. I turned on windows authentication in the web.config <authentication mode="Windows" /> and set up IIS to not allow anonymous access. My browser is set up to auto detect the proxy server, so IE/Firefox can access outside pages, so I added code to auto-detect the proxy server.
9
1999
by: David | last post by:
With a non-server app there is one instance of the program running and one user 'using' it at a time. With this scenario I'm pretty comfortable with variable scope and lifetime. With a server app there is one instance of the program running but several simultaneous clients connecting to and 'using' it. When I think about this I'm wondering what this may add to what needs to be considered for scope and lifetime... is a scenario created where...
3
2506
by: UltimateBanoffee | last post by:
Hi, I'm using asp.net 2.0 and I have an understanding issue here! I don't quite understand when the available threads in the ThreadPool are ever used. The application I have running doesn't use ThreadPool.QueueWorkItem, and doesn't create any other Threads. So say I have 100 users access my application at the exact same time and they all call on an aspx that takes a couple of seconds to process. I gather 100 sessions are active, but...
4
6483
by: raylopez99 | last post by:
Compound question: first, and this is not easy, if there's a way to detect multiple simultaneous key presses in C# let me know (in the below code, keys c and d being pressed simultaneously or nearly so). I researched this and for C# (as opposed to MFC) there is no library function, and no easy way, though some code on the net suggested that you set up a thread that 'lives' for a certain time, then, if keys are pressed in that certain...
0
10134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11296
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9858
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8218
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6298
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.