using System.Collections.Generic;
using System.Threading.Tasks;
public static void Main()
var accounts = GenerateAccount();
var accountsProcess = new List<Account>();
var taskList = new List<Task>();
foreach (var account in accounts)
var bob = accountsProcess;
taskList.Add(new Task(() => ProcessAccount(bob)));
accountsProcess = new List<Account>();
accountsProcess.Add(account);
Parallel.ForEach(taskList, t =>
Task.WaitAll(taskList.ToArray());
if (accountsProcess.Count > 0)
ProcessAccount(accountsProcess);
public static List<Account> GenerateAccount()
var accounts = new List<Account>();
for (int i = 0; i <= 1000; i++)
var account = new Account();
account.first = first + i;
account.second = second + i;
public static void ProcessAccount(List<Account> accounts)
Console.WriteLine(accounts.Count);
foreach (var account in accounts)
Console.WriteLine(account.first + account.second);