I have a created a background job which processes users(ex: 2000 users, calling other apis and adding to database), I have divided users into few chunks (ex: 10 chunks) and processing them in tasks for each chunk.
I need to get progress of how many users getting processed from each individual task and so that I can sum and take it as progress.
How can I do that?
private void CallingMethod()
{
List<Task> allTasks = new List<Task>();
allTasks.Add(Task.Run(() => ProcessUsers(usersList1));
allTasks.Add(Task.Run(() => ProcessUsers(usersList2));
allTasks.Add(Task.Run(() => ProcessUsers(usersList3));
await allTasks;
int GetCountsFromTasks????
}
private async Task ProcessUsers(List<User> usersList)
{
int processedUsers = 0;
foreach(var user in usersList)
{
// Processing of users
//End
processedUsers++; // Need to send this count to calling method
// after each user completion
}
// send results object as well to calling method which contains usernames,
// success/fail for each user at end of task
}