private void button1_Click(object sender, EventArgs e) { var modifiedPlayers = new List <ScorablePlayer>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.DefaultCellStyle.BackColor == Color.LightSalmon) { // Add to excluded _excluded.Add(_sps.Where(p => p.Name == (string)row.Cells[0].Value).First()); } if (row.DefaultCellStyle.BackColor == Color.LightGreen) { // Add to keeper _keepers.Add(_sps.Where(p => p.Name == (string)row.Cells[0].Value).First()); } } foreach (var p in _sps) { if (_excluded.Contains(p)) { continue; } double cutfactor; if (p.Tournaments != 0) { cutfactor = (double)p.CutsMade / p.Tournaments; } else { cutfactor = 2.0 / 3.0; } double modfactor; try { modfactor = 1.0 + (p.CupPoints / p.Events - avgPts) / (10.0 * stddevPts); } catch (DivideByZeroException) { modfactor = 1.0; } var top10modFactor = Math.Pow(1.05, p.Top10s); modifiedPlayers.Add(new ScorablePlayer(p.Name, p.Salary, p.Points * cutfactor * modfactor * top10modFactor, p.Multi, p.Tournaments, p.CutsMade, p.Top10s, p.Earnings, p.CupPoints, p.Events)); } teams = new SimpleTeamChooser().ComputeTopTeams((IEnumerable <ScorablePlayer>)modifiedPlayers, _keepers); var plzWait = new OptimizingWaitForm(); plzWait.Show(); teams.ContinueWith(((best_teams) => { var best = best_teams.Result; plzWait.Hide(); this.Hide(); var Summary = new SummaryForm(best); Summary.Closed += (s, args) => this.Close(); Summary.Show(); }), TaskScheduler.FromCurrentSynchronizationContext()); }