There is an API Async method (GetMatrix
) which takes a row number of a square matrix as input parameter and responds back with the values in that row.
I need to construct the whole matrix by calling the API multiple times (row size of the matrix times).
Right now I have initialized a jagged array and I'm sending async calls to that API in a "For loop" like below.
var matrix = new int[size][];
for (int i = 0; i < size; i++)
{
matrix[i] = await GetMatrix(i);
}
It's taking a decent amount of time to construct the whole matrix if the matrix is of huge size (like 1000 rows).
Can we create parallel tasks in conjunction with the above async calls? I think it will be faster than just async calls. How can we do that in C#?