ServicePointManager limit download?

H

Harold

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?
 
H

Harold

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 ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top