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