private void RunSavedGenom(object sender) { _newPop = true; ((Button)sender).IsEnabled = false; new Thread(() => { _mainRun?.Join(); _newPop = false; _mainRun = new Thread(() => { string path = null; Genom brain; Dispatcher.Invoke(() => { OpenFileDialog choofdlog = new OpenFileDialog(); if (choofdlog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = choofdlog.FileName; } }); if (!string.IsNullOrEmpty(path)) { brain = ObjectCopier.Load <Genom>(path); } else { return; } while (!_newPop) { brain.Fitness = 0; Game game = new Game(brain, _toShow ? this : null); while (game.move()) { if (_newPop) { game.clearField(); return; } if (_toShow) { Thread.Sleep(_timeout); } } game.clearField(); Console.WriteLine("Score: " + brain.Fitness); } }); _mainRun.Start(); Dispatcher.Invoke(() => ((Button)sender).IsEnabled = true); }).Start(); }