By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,997 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,997 IT Pros & Developers. It's quick & easy.

ServicePointManager limit download?

P: n/a
Hi,

I'm writing software which should download some files. I want to limit
the number of simultanioulsy downloads to two. I'm using the
ServicePointManager object for this. But I still can download more then
two files at the same time. When I use perfmon with the counter "Web
service/current connections" the number of connection are more then
two. And I am sure that I am the only user ;-)

In the init of the application the following code will be called:

Dim uri As New Uri("http://server/file.zip")
sp = ServicePointManager.FindServicePoint(uri)
sp.ConnectionLimit = 2

ServicePointManager.DefaultConnectionLimit = 2

After this I start e.g. 10 threads with the following code:

Dim myReq As HttpWebRequest
myReq = WebRequest.Create("http://server/file.zip")

myReq.Credentials = CredentialCache.DefaultCredentials
myReq.Method = "GET"
myReq.ConnectionGroupName = "MyGroup"

Dim myResponse As HttpWebResponse = myReq.GetResponse()

Dim stream As Stream = myResponse.GetResponseStream()
Dim bytes(1024) As Byte

While (stream.Read(bytes, 0, 1024) > 0)
End While

myResponse.Close()

By the way: what should happen when I execeed two connections? Should
an exception be thrown? Or will the other downloads wait?

May 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I found it!
I was testing with a local website on the same machine as the test
application....
When I changed the url to a remote website the connections were limited
to 2.

Hmmm I didn't find this in the documentation ;-)

May 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.