Between the two pieces of code, Parallel.ForEach() will be more efficient, since it processes several elements in one Task one after another.
But both of them will use as many threads as ThreadPool will be, which is not very good in this case. This is because ThreadPool good at guessing the optimal number of threads if you have a very short CPU Task s, which is far from the case.
Because of this, I believe that the best option is to manually limit the degree of parallelism to a small number (you will need to measure to find out which number gives the best results):
List<ServiceMemberBase> list = …;
It would be even more efficient if you could make the web service call asynchronously. Doing this and limiting the degree of parallelism at the same time is not very simple if you are not in C # 5. If you were in C # 5 and if you also updated Proxy to support asynchronous task-based template (TAP), you can use TPL data stream for more efficient code execution:
var actionBlock = new ActionBlock<ServiceMemberBase>( async member => { var result = await Proxy.InvokeAsync(member);
svick
source share