I need to increase the performance of a ForEach.
//Pseudocode
foreach (item i item in items)
{
//Call service to open DB conn and get data
}
Within this loop make a call to a service that opens a session sqlserver, gets data from the database and closes the session, so for each iteration.
What I can do?.
Thanks.
Well that does sound like a perfectly good use of
Parallel.ForEach– so have you tried it?You may well want to specify options around the level of parallelism etc – and make sure your connection pool supports as many connections as you want. And of course, measure the performance before and after to make sure it’s actually helping.