views:

29

answers:

0

I have a controller that looks like the following:

foreach(var setting in userSettings)
{
    //connect to db here and run a 500ms query
}

The userSettings varies per user and so sometimes there are 2 settings which means 2 500ms queries need to run, while sometimes the user has 15 settings, meaning 15 500ms queries will run.

Since this isn't async right now, when there are 15 settings it will be 15*500ms slow.

I want to make these async. However, based on all the documentation I read the Completed delegate needs to know how many parameters there are. But since userSettings varies, the number of parameters that will be completed also varies.

Is there any good way to make this async so that the db queries run concurrently?