I have a method that I call 8 times with different parametres. I use
AvailableYears.AsParallel()
.Select<Int32,DateUsedByThread>(x => GetDataForYearWorker(x,CIF))
.ToList();
GetDataForYearWorker gets the response from a webservice synchronously. It uses very little computing power on my asp.net application, but it ussualy takes 3-5 sec for each webservice response. Because the calls to the webservice are independent of eachother, I want to make tham all at the same time. But it looks like only 2 threads can run at the same time. Why is this and how can I have 8 threads working at the same time?
By default .AsParallel()
will spin up one thread per core on the machine running the query. If you wish to alter this behavior look at WithDegreeOfParallelism.
AvailableYears.AsParallel().WithDegreeOfParallelism(5)
.Select<Int32,DateUsedByThread>(x => GetDataForYearWorker(x,CIF))
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With