I have many different stored procedures that I want to disable in Parallel to improve the performance of my MVC web application. These stored procedures collect information from several sources and return different types of data. For simplicity, let's say I had only two that returned different complex data types:
- ups_Proc1 returns a list of usp_Proc1
- usp_Proc2 returns a list of usp_Proc2
etc....
I could make one of these numbers, but that would launch them in a series:
List<usp_Task1> taskOneResult = await db.usp_Task1(parms).AsQueryable() .ToListAsync(); List<usp_Task2> taskTwoResult = await db.usp_Task2(parms).AsQueryable() .ToListAsync();
The solutions I saw use await Task.WhenAll() and you pass in an array of tasks, but my tasks are different types of returned data. So, how does one of them run several stored procedures in parallel when working with various complex return types?
UPDATE-5/20/2015
Finally, a working solution has appeared that, I believe, processes all tasks in parallel. I had to use the Task.Factory.StartNew() command to create each function as a task to be passed to Task.WaitAll() .
I applied all this to a new class that contained List<> for each returned type of the stored procedure that I am working with, which allows me to process all my business logic. The code in the constructor looked something like this:
var task1 = Task.Factory.StartNew(() => CallStoredProc1(parms)); var task2 = Task.Factory.StartNew(() => CallStoredProc2(parms)); var taskList = new List<Task> { task1, task2 }; Task.WaitAll(taskList.ToArray());
CallStoredProc1() and CallStoredProc2() are private void methods where I make calls to the stored procedure and handle the data transformation.
Any feedback is greatly appreciated!
source share