public Form1() { InitializeComponent(); using (InvestmentEntities entities = new InvestmentEntities()) { var allInvestments = entities.MutualFundViews.Where(m => m.MutualFundID > 0).ToList(); var investmentList = allInvestments.Select(i => i.MutualFundSymbol).Distinct().ToList(); ReturnOnInvestment header = new ReturnOnInvestment("Fund Name", "Description", "Investments", "Dividends", "Current Value", "APY", "Yield L12", "Since"); flowLayoutPanel1.Controls.Add(header); CurrentValue = 0.0M; CurrentValue_ForLast12Calc = 0.0M; DateTime last12Start = entities.GetLast12StartDate().First().Value; //List<Task> taskList = new List<Task>(); foreach (String investment in investmentList) { GetInvestments(allInvestments.Where(f => f.MutualFundSymbol == investment).ToList(), investment, last12Start, entities); //var task = Task.Factory.StartNew(() => GetInvestments(allInvestments, investment)); //taskList.Add(task); } //Task.WaitAll(taskList.ToArray()); foreach (var control in returns.OrderBy(r => r.FundName)) { flowLayoutPanel1.Controls.Add(control); } Investments = allInvestments.Where(i => i.ReturnType == "Investment").Sum(i => i.Amount); Gains = allInvestments.Where(i => i.ReturnType != "Investment").Sum(i => i.Amount); ROI = Convert.ToDecimal(Calculations.IRR.solveIRR(allTransactions, Convert.ToDouble(CurrentValue), 1, 1000, DateTime.Now)); Decimal ROILast12 = Convert.ToDecimal(Calculations.IRR.solveIRR(transactionsLast12, Convert.ToDouble(CurrentValue_ForLast12Calc), 1, 1000, DateTime.Now)); flowLayoutPanel1.Controls.Add(new ReturnOnInvestment("Totals", "", this.Investments.ToString("c"), this.Gains.ToString("c"), this.CurrentValue.ToString("c"), this.ROI.ToString("p"), ROILast12.ToString("p"), "")); } }